DataGridView ClearSelection() behavior
-
Hello, I have noticed a particular behavior in a program I am developing. I am interested if anyone might have a solution in mind. I've got a TabControl with 6 TabPages on it. Each TabPage has a DataGridView on it and when the user selects a row on one of these DataGridViews, my program responds in some way that isn't germane to the problem. The desired behavior is that the user is always presented, when selecting a TabPage, with a DataGridView with all rows unselected. Here is a code snippet to illustrate what I currently do to accomplish this:
private void tabControlPageSelected(object sender, TabControlEventArgs e) { (e.TabPage.Controls[0] as DataGridView).ClearSelection(); }
The behavior that I see is that, despite explicitly calling DataGridView.ClearSelection() after the population of these DataGridViews and again in response to the Selected event using the code above, as I click through the tab pages, the first row of each is initially highlighted. Once I have navigated to a new tab page and navigate back to the previous one, the highlighting is gone, as desired. Code to test if any rows are selected tells me that none are, and it appears that the highlighting is simply a cosmetic annoyance, but that annoyance is confusing to the user and my primary goal is to make the program intuitive and free from annoyances. Any ideas? Thanks much, Matt It isn't enough to do well in life. One must do good when and where one can. Otherwise, what's the point? -
Hello, I have noticed a particular behavior in a program I am developing. I am interested if anyone might have a solution in mind. I've got a TabControl with 6 TabPages on it. Each TabPage has a DataGridView on it and when the user selects a row on one of these DataGridViews, my program responds in some way that isn't germane to the problem. The desired behavior is that the user is always presented, when selecting a TabPage, with a DataGridView with all rows unselected. Here is a code snippet to illustrate what I currently do to accomplish this:
private void tabControlPageSelected(object sender, TabControlEventArgs e) { (e.TabPage.Controls[0] as DataGridView).ClearSelection(); }
The behavior that I see is that, despite explicitly calling DataGridView.ClearSelection() after the population of these DataGridViews and again in response to the Selected event using the code above, as I click through the tab pages, the first row of each is initially highlighted. Once I have navigated to a new tab page and navigate back to the previous one, the highlighting is gone, as desired. Code to test if any rows are selected tells me that none are, and it appears that the highlighting is simply a cosmetic annoyance, but that annoyance is confusing to the user and my primary goal is to make the program intuitive and free from annoyances. Any ideas? Thanks much, Matt It isn't enough to do well in life. One must do good when and where one can. Otherwise, what's the point?both of these ways are basically cheating :)(they still work), but maybe in the onLoad you could do a foreach statement that deselects everything, and if that doesn't work, you could try making a foreach that selects every tab page once before the form is actually shown. Sorry for a lack of a better answer. X|