I’ve got a DataGridView in a modal window with a list of options for my program. The grid has two collumns. The first one contains a checkbox for selecting that option, the seccond is the name/description of that option. The winform also contains OK and cancel buttons but that’s beside the point. The code below does what I want it to. Because of the FullRowSelect property the checkbox is checked/unchecked in you click anywhere withint that row. It does however not show a blue background or a dotted line around the current row anymore. How would I be able to add this without loosing any of the current functionality?
EDIT: To elaborate; what I want is to once again enable the dotted line and/or blue background on the selected row/cells. It looks like the code I have currently somehow disables this…
Relevant current code:
public OptionsForm()
{
InitializeComponent();
OptionsRoot = Options.GetReadOnlyRoot(OptionsBannersNameValueList.GetNameValueList(Settings.Default.OptionsBanners));
optionsBannersDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
optionsBannersDataGridView.MultiSelect = false;
optionsBannersDataGridView.RowPrePaint += new DataGridViewRowPrePaintEventHandler(optionsBannersDataGridView_RowPrePaint);
InitUI();
Closing += MyFormClosing;
BindingSourceTree = BindingSourceHelper.InitializeBindingSourceTree(components, rootBindingSource);
}
private void optionsBannersDataGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
e.PaintParts &= ~DataGridViewPaintParts.Focus;
}
What I finally ened up doing was remove most of the code mentioned above, as it really didn’t do much. for some reason when I set the properties in visual studio it did not work, but now it does. I don’t know what happened there but thats beside the point.
The constructor now looks like this:
The properties are set in the visual studio GUI instead. SelectionMode is set to FullRowSelect and MultiSelect is set to false.
I still didn’t get the focus I wanted so I set the backcolor of of the selected row to blue and the forecolor to white in visual studio. This now works like I wanted it to.
I still don’t know why the properties were not getting set properly earlier, but at least it works now 😛