How can I stop a DataGridView with a Filter set from moving too far down the list?
Consider a dataGridView bound to some database. The binding source for the dataGridView has a filter that will only show where the description field is empty.
The idea is that the user will only see records with this value, records that require their attention. The user will always change that value to something else.
My problem is once they move to the next row through either the enter or tab key, it filters almost after they have moved to the next row, moving its position to the row below where they should be.
Is there a way to control this behavior so that the position doesn't skip to the next row after filtering o开发者_如何学Goccurs? I don't want to do separate fill's on the dataset for this particular question though I am aware that is it a solution. I would like to know how to control the filtering better, if possible.
EDIT
Worth noting that I have not wired up any events to the datagridview, this is out-of-the-box behavior of dragging the control onto the form, hooking up a binding source to it from a dataset, and filling the dataset on the form_load event.
EDIT
Example of current behavior - (C) represents cursor location
User keys a name in row #2 and sets the status to TRUE
R1 - John Doe FALSE
R2 - Jane Doe TRUE (C)
R3 - Rob Doe FALSE
R4 - Joe Doe FALSE
User presses return (or tab, it doesn't matter which, for this example its enter...)
R1 - John Doe FALSE
R3 - Rob Doe FALSE
R4 - Joe Doe FALSE (C)
The current selected row is now row 4 where it really should be row 3. If I had not changed the value from false to true for R2, it wouldn't have filtered and would have correctly moved me to row 3
EDIT
Resurrecting this from the dead as I have not received a suitable solution to this problem. Anybody out there have a creative idea? ^_^
I had same problem with DataGridView
a while ago.
I wanted to change the behavior of the Enter key to move the selected rows up instead of down. Here is what I did, I hope it helps you. I made a control that inherits DataGridView, and overrided ProcessCmdKey
and did the changes in it. In your case what you want to do is:
public partial class MyDataGridView : DataGridView
{
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Tab || keyData == Keys.Enter)
{
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
}
This will stop the gridView from moving to next row when pressing Enter or Tab. I hope it works for you, if it does not please say what is the problem.
精彩评论