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. C#
  4. how to get the cell value of a DataGridView 's click event

how to get the cell value of a DataGridView 's click event

Scheduled Pinned Locked Moved C#
debugginghelptutorial
2 Posts 2 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.
  • K Offline
    K Offline
    kssknov
    wrote on last edited by
    #1

    scenario: when i click the datagridview's cell, immediately i need to pass this cell to a WHERE condition to select the remaining fields of the same row.(ie)the gridcell value is an ID value , remaining fields of the ID should be retrieved to textboxes. I wrote code as private void DataGrdVw1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dsGridToTxtBx == obj._selectGridCellAreaDetails(DataGrdVw1.CurrentCell.Value.ToString())) { txtAreaName.Text = dsGridToTxtBx.Tables[0].Rows[0].ItemArray[1].ToString(); txtRegion.Text = dsGridToTxtBx.Tables[0].Rows[0].ItemArray[2].ToString(); txtLocORinterSt.Text = dsGridToTxtBx.Tables[0].Rows[0].ItemArray[3].ToString(); } } Pls help me. I cant trace the datagridview's click event. My above code has no effect in form. :((

    ssk

    U 1 Reply Last reply
    0
    • K kssknov

      scenario: when i click the datagridview's cell, immediately i need to pass this cell to a WHERE condition to select the remaining fields of the same row.(ie)the gridcell value is an ID value , remaining fields of the ID should be retrieved to textboxes. I wrote code as private void DataGrdVw1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dsGridToTxtBx == obj._selectGridCellAreaDetails(DataGrdVw1.CurrentCell.Value.ToString())) { txtAreaName.Text = dsGridToTxtBx.Tables[0].Rows[0].ItemArray[1].ToString(); txtRegion.Text = dsGridToTxtBx.Tables[0].Rows[0].ItemArray[2].ToString(); txtLocORinterSt.Text = dsGridToTxtBx.Tables[0].Rows[0].ItemArray[3].ToString(); } } Pls help me. I cant trace the datagridview's click event. My above code has no effect in form. :((

      ssk

      U Offline
      U Offline
      Ujjaval Modi
      wrote on last edited by
      #2

      Hi, First of all check whether the Handler you have defined is handling the cell's content click. It will be called only when you click on the cell's content. Its better to define a Handler for CellClick Event. To access the current cell's value you can use following : GridView1.CurrentRow.Cells("ID").Value

      Regards, Ujjaval Modi

      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