Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Hiding a Button in a DataGridView

Hiding a Button in a DataGridView

Scheduled Pinned Locked Moved Windows Forms
helptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    john_paul
    wrote on last edited by
    #1

    I have a DataGridView in a windows form that I need to be able to make the datagridviewbutton visible or invisible depending on the value of another column. I can not figure out how to make this happen when I bind the datatable to the datagridview. Any help would be appreciated. Thanks John

    L F 2 Replies Last reply
    0
    • J john_paul

      I have a DataGridView in a windows form that I need to be able to make the datagridviewbutton visible or invisible depending on the value of another column. I can not figure out how to make this happen when I bind the datatable to the datagridview. Any help would be appreciated. Thanks John

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      For that you need to use RowDataBound event. Try following code.

      protected void MyDataGrid_RowDataBound(object sender, GridViewRowEventArgs e)
      {
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
      if (condition)
      {
      (e.Row.FindControl("buttonid") as Button).Enabled = false;
      }
      }
      }

      HTH

      Jinal Desai - LIVE Experience is mother of sage....

      1 Reply Last reply
      0
      • J john_paul

        I have a DataGridView in a windows form that I need to be able to make the datagridviewbutton visible or invisible depending on the value of another column. I can not figure out how to make this happen when I bind the datatable to the datagridview. Any help would be appreciated. Thanks John

        F Offline
        F Offline
        freakyit
        wrote on last edited by
        #3

        hi man, this could be a possible solution but never tested.. In the CellValueChanged event you have to check your specified cell against your condition and than try: dataGridView1.Rows[rowIndex].Cells[buttonCell].ReadOnly = true; or dataGridView1.Rows[rowIndex].Cells[buttonCell].Frozen = true; hope i could help :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups