Answered by:
Why is a cell ALWAYS selected in my DataGridView

Question
-
I just dont get this one. No matter what I do, whenever I load my form with a DataGridView, which has two DataGridViewComboBoxColumns inserted, the first cell is always selected by default. I tried setting the focus() for one of my buttons but that did not change anything. I even tried cycling through the selectedCells property of the DataGrid and setting the Selected property to false. NO WHERE in my code, as far as Im aware, do I tell the DataGrid to have a selected cell. Is there some special way I have to do this because of the ComboBoxes? If someone can help and needs to see the code, let me know.. thanks...Wednesday, August 16, 2006 8:52 PM
Answers
-
Well I figured out how to get around this, but Im still not sure why this happens. It seems that during the Form.Show the DataGridView Cell gets selected. So I created a .Show Event and entered CurentCell = null and the form loads then the cell is deselected. Im still curious why I have to do this at all.Thursday, August 17, 2006 6:49 PM
All replies
-
Hi,
Have you tried
after you get the data? Hope this helps.
dataGridView1.ClearSelection();
Thursday, August 17, 2006 3:49 AM -
That did not work either. No matter what I do, the first ComboBox Cell of the first COmboboxcolumn in the datagridview is still selected.Thursday, August 17, 2006 3:39 PM
-
Ok, I think I know where in my code this is happening, but I just dont know what to do about it. This is a form that loads from another form, within a bigger application. This is the code used to load the form:
ModuleGroupListEditor glEd = new ModuleGroupListEditor();glEd.Show();
After the first line, the form loads and calls that ClearSelection(). But, when the Form Shows, it appears with that first cell selected. I took out the DataGridViewComboBoxColumns to see if they were to blame and the same thing happens. Any ideas?
Thursday, August 17, 2006 4:05 PM -
Well I figured out how to get around this, but Im still not sure why this happens. It seems that during the Form.Show the DataGridView Cell gets selected. So I created a .Show Event and entered CurentCell = null and the form loads then the cell is deselected. Im still curious why I have to do this at all.Thursday, August 17, 2006 6:49 PM
-
Glad to hear that you solved the problem. As you said, the ClearSelection should be placed after the Show function. WhenFriday, August 18, 2006 6:23 AM
-
Thanks for the help. Why does this not work in the Form.Load event?Friday, August 18, 2006 3:20 PM