Hello,
When using the DataGridView in a modal dialog, (I'm using the DataGridView
in a generic lookup dialog) I'm having a couple of issues I hope someone can
help me with:
- 1 -
I have FullRowSelect for my selection mode. I have two buttons assigned to
the typical Accept and Cancel button properties on the form. Hitting ESC
works for cancelling out of the form, but hitting enter causes the selected
row in the DataGridView to move down one. I would like the enter key to
trigger the accept button. If the DataGridView does not have focus, hitting
enter works properly closing the dialog. I've tried intercepting the enter
key at the form level and setting the DialogResult to ok but even when I set
handled = true, the DataGridView still moves down to the next record. Any
thoughts?
- 2 -
The generic selection dialog, have among its optional properties, to pass in
a StringCollection of pre-selected items. The pre-selected items are found
using the following code:
foreach (string s in preSelectedItems)
{
string tmp = string.Format("{0} LIKE '{1}%'", lookupField, s.ToUpper());
DataRow[] rows = list.Table.Select(tmp);
if (rows.Length > 0)
{
int position = bindingSource.Find(lookupField, rows[0][lookupField]);
if (position >= 0)
grdList.Rows[position].Selected = true;
}
}
My problem is the pre-selected items are not selected once the dialog is
modally shown. Just the first row of the DataView that was passed in. The
BindingSource returns a proper row position but it seems like something
resets the view once the form is actually shown.
Thanks for any suggestions on these two items!