none
how to select a grid cell RRS feed

  • Question

  • Hi all,

    I am using c sharp and i have a grid with table data. When a user give the row and column index i want to highlight (select) that cell in the grid.How may i do this. Please help.

    Thanx

    Monday, April 25, 2011 4:11 AM

Answers

  • Not a problem. Just set the CurrentCell property as well.

           int column = 3;
           int row = 2;            

           dataGridView1.ClearSelection();            
               
           dataGridView1.CurrentCell = dataGridView1[column, row]; 
           dataGridView1[column, row].Selected = true; 


    Please mark this post as answer if it solved your problem. Happy Programming!

    • Marked as answer by Creative_Pro Wednesday, April 27, 2011 5:39 AM
    Wednesday, April 27, 2011 5:34 AM

All replies

  • Hi all,

    The actual proble I have is like this. I have a grdi with table data and when the user click the Edit button it brings a new form with selected row data values. Once user save changes, I commit that changes and close the child form. But when it comes to the parents grid, it not refreshing the new values. So I reassinged the data source of the grid using Linq query. But the record pointer of the grid is always at top cell.I want to keep that record to the previous edited record. Is there any way to achiew this? please help.

    Monday, April 25, 2011 5:02 AM

  • Hi anu,

    To Select any Cell, Set the Selected property to true. See the below example.

           int column = 3;
           int row = 2;            

           dataGridView1.ClearSelection();            

           dataGridView1[column, row].Selected = true; 

    Hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Wednesday, April 27, 2011 3:08 AM
  • Hi Adavash,

    The above code snippet is working. Thank you very much. But there is an arrow in the grid to point the grid record. That pointer is still in the top even though the another cell is selected. Is there any way to move that record pointer to the relevant record in the grid. Please help. And thank you for the reply again.

    regards.

    Wednesday, April 27, 2011 3:41 AM
  • Not a problem. Just set the CurrentCell property as well.

           int column = 3;
           int row = 2;            

           dataGridView1.ClearSelection();            
               
           dataGridView1.CurrentCell = dataGridView1[column, row]; 
           dataGridView1[column, row].Selected = true; 


    Please mark this post as answer if it solved your problem. Happy Programming!

    • Marked as answer by Creative_Pro Wednesday, April 27, 2011 5:39 AM
    Wednesday, April 27, 2011 5:34 AM
  • Hi Adavesh,

    Thank you very much for your reply. This is working and solved my problem.Happy programming.

    Regards,

    Anu

    Wednesday, April 27, 2011 5:40 AM