Click here to Skip to main content
15,885,868 members
Articles / Programming Languages / C# 4.0

Selected datagridview row eror

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
9 Nov 2012CPOL 3.8K  
Hello,I have this little problem.I have datagridview and on CellClick event I have this code.dg.Rows[e.RowIndex].Selected = true;I use this event to select row on click on any cell, but now here comes the problem when I click on the Header of column to sort the column, I cant.I...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
9 Nov 2012Gautam Raithatha
u can check for Header row in CellClick event and dont process for header row. Header row has index -1. so try this:private void gv_CellClick(object sender, DataGridViewCellEventArgs e){ if (e.RowIndex != -1) { //Your code }}
Please Sign up or sign in to vote.
9 Nov 2012shonezi
I changed code to thisdg.CurrentRow.Selected = true;now it works, but still its on CellClick event, maybe something different has to be done if it should not be on CellClick event
Please Sign up or sign in to vote.
9 Nov 2012Karthikeyan Mathiyalagan
Hi, Cell click event is not good, you try to use Gridview RowCommand event is to be better

License

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


Written By
Serbia Serbia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions