Reputation: 143
I am using the DataGridView
bound to a database. I have a button that is disabled. When a row is selected, not by clicking in a cell but on the row selection pane, I want to respond to an event and enable that button.
Upvotes: 2
Views: 5409
Reputation: 33183
Arguably the 'correct' event to use to detect when a DataGridView row is selected is SelectionChanged
.
dataGridView1.SelectionChanged += new EventHandler(dataGridView1_SelectionChanged);
void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
// code that happens after selection
}
The problem with this event is that the event signature only has a plain EventArgs with not special information about the DataGridView. Also this responds to any source of the selection changing, not only the row header being selected.
Depending on your exact needs the bemused's answer of RowHeaderMouseClick
could well be better.
Upvotes: 0
Reputation: 1309
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
AddRowSelectToGridView(gridView);
base.Render(writer);
}
private void AddRowSelectToGridView(GridView gv)
{
try
{
foreach (GridViewRow row in gv.Rows)
{
row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(gv, "Select$" + row.RowIndex.ToString(), true));
}
}
catch (Exception ex)
{
}
}
try this code,u can select the row..
Upvotes: 2
Reputation: 66501
Well, there's the RowHeaderMouseClick event. From there, you can get e.RowIndex to determine which row the click occurred on.
Upvotes: 3