Domanda

I'm trying to add some rows to a DataGridView.

After I get past the 12th row it stops displaying.

When I break in via the debugger, I can see that my DGV has all the rows. They just don't get displayed.

I've tried doing the equivalent of giving it a swift kick (moving focus around, moving the selection to the last item, Application.DoEvents() and so on, but to no avail).

OtherButton.Focus();
MoveFocusToNext();
_policyDataGrid.Focus();
_policyDataGrid.Rows[_policyDataGrid.Rows.Count - 1].Cells[0].Selected = true;
Application.DoEvents();
_policyDataGrid.Rows[0].Cells[0].Selected = true;
Application.DoEvents();

Does anyone know a workaround?

NB: I've seen a lot of posts where the DataGridView has a binding source, but this one doesn't. It's got a lot of manual Rows.Add().

È stato utile?

Soluzione 2

This ended up working for me:

_policyDataGrid.ScrollBars = ScrollBars.None;
_policyDataGrid.ScrollBars = ScrollBars.Vertical;

But there's an Rpc wait in there in my app, so this might not be real time enough for other people.

Altri suggerimenti

Try using the CurrentCell property:

dgv.CurrentCell = dgv.Rows[dgv.Rows.Count - 1].Cells[0];

This is with the AllowUserToAddRows property set to false.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top