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. C#:Problem in DataGridView CellMouseClck Event

C#:Problem in DataGridView CellMouseClck Event

Scheduled Pinned Locked Moved C#
helpcsharp
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

    hi all, any body pls help me to solve my problem. Though my code is right (i feel) i couldnt achieve the result i expect , i tried in all means, any one pls solve my headache!. private void DataGrdVw1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { string CurrentSelValue; CurrentSelValue = DataGrdVw1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); txtAreaName.Text = CurrentSelValue; } it doent works!. i tried with cell mouse down event also no use. private void DataGrdVw1_CellMouseDown(object sender,DataGridViewCellMouseEventArgs e) { this.GrdText.Text = DataGrdVw1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); } i need to show the current cell s text in a text box when the datagridview's cell is clicked with mouse, or arrow keys pls help kssk

    KSSK

    M 1 Reply Last reply
    0
    • K kssknov

      hi all, any body pls help me to solve my problem. Though my code is right (i feel) i couldnt achieve the result i expect , i tried in all means, any one pls solve my headache!. private void DataGrdVw1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { string CurrentSelValue; CurrentSelValue = DataGrdVw1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); txtAreaName.Text = CurrentSelValue; } it doent works!. i tried with cell mouse down event also no use. private void DataGrdVw1_CellMouseDown(object sender,DataGridViewCellMouseEventArgs e) { this.GrdText.Text = DataGrdVw1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); } i need to show the current cell s text in a text box when the datagridview's cell is clicked with mouse, or arrow keys pls help kssk

      KSSK

      M Offline
      M Offline
      martin_hughes
      wrote on last edited by
      #2

      Use the DataGridView's CellEnter event, and then use the CurrentCell property: private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e) { label4.Text = dataGridView1.CurrentCell.Value != null ? dataGridView1.CurrentCell.Value.ToString() : String.Empty; } Notice that I'm also checking here if the cell value is null, and setting the textbox text to String.Empty if it is, otherwise you get a nasty Null Reference Exception when trying to call ToString() a non-existent value.

      "On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't. "I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it." -Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.

      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