Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
From the below code am able to show the selected data from datagridview to textbox but it happens only when i click on the content but when i click on the cell where the content is not there its not displaying the data in the text fields.

C#
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
       {
           if (e.RowIndex >= 0)
           {
               DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];

               TxtName.Text = row.Cells["Name"].Value.ToString();
               TxtPath.Text = row.Cells["Path"].Value.ToString();


           }
       }
Posted
Updated 16-Jun-15 4:59am
v2
Comments
CHill60 16-Jun-15 10:58am    
I'm a little confused. If you click on a row that contains data it works as you expect? If you click on a row that doesn't contain data ("where the content is not there") what do you expect to see?
Shaik Izaz 16-Jun-15 11:02am    
what i mean to say is, Assume if the cell width is 100 and the content width is 50 and when i click on the content it is displying on the textbox but when i click on the remaing empty cell it's not displaying the content in the textbox

1 solution

This is expected behaviour as you have used the CellContentClick method. It only fires when you click the actual content and not the white space after it.

If you want this to happen wherever you click in the cell then use the CellClick event instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900