Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai friends,
the below code for selecting datagridview rows value to textbox of my windows form

C#
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
       {
           //if (dataGridView1.CurrentRow.Index == 0)
          // {
             //  MessageBox.Show("please dont select Header columns");

          // }

           if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "Select")
           {
               //int index = dataGridView1.CurrentRow.Index;

               textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells["School_id"].Value.ToString();
               textBox1.ReadOnly = true;
               textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells["School_name"].Value.ToString();
           }
           else
           {
               MessageBox.Show("please enter select button only");
           }

           }
       }


Here "select" is a gridview button.

suppose when i wrongly click the head row of datagridview the error would ocuur as indexoutofboundexception .please help to inactive this head row.
thank you in advance
Posted
Updated 25-Jul-12 8:36am
v2
Comments
[no name] 25-Jul-12 14:47pm    
It's not clear what you want to do as you say 3 different things. The row index for the header is -1 so if e.RowIndex == -1 either hide the header row, or make the header inactive, or ignore the click whichever you really want to do.
baskaran chellasamy 25-Jul-12 15:00pm    
i want ignore the click.please tell me how to do it
[no name] 25-Jul-12 15:17pm    
Really?!? if (e.RowIndex == -1) return;
Clifford Nelson 25-Jul-12 17:03pm    
Helps if you include the environment, assuming WinForms

1 solution

See the following http://msdn.microsoft.com/en-us/library/2x16tybz.aspx[^]. The answer is:

dataGridView1.ColumnHeadersVisible = false;
 
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