I've got a DataGridView with VirtualMode set to true, and data being supplied via the CellValueNeeded event. Everything is working fine, but... the last row has no data in it. I setup the columns in the designer and several of them are Link columns, those show up just no data. I verified the data is in my source object (I'm binding to a IEnumerable) and that the RowCount is set correctly.
If I add another row to the source, it won't show up but the one that was previously invisible will show up.
This is NOT a problem with AllowUserToAddRows - it's set to false. The row is just blank, and the CellValueNeeded event doesn't appear to ever be called for that item in the IEnumerable.
I'm pulling my hair out here. Please help.
gvPilots.VirtualMode = true;
gvPilots.AutoGenerateColumns = false;
gvPilots.AllowUserToAddRows = false;
IEnumerable<pilot> _pilotData = jamboree.pilots.Where(p => p.sync_state != (byte)SyncState.IsDeleted);
gvPilots.RowCount = _pilotData.Count();
private void gvPilots_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
{
if (e.RowIndex == this.gvPilots.RowCount - 1) return;
pilot thisPilot = null;
thisPilot = this._pilotData.ElementAt(e.RowIndex);
switch (this.gvPilots.Columns[e.ColumnIndex].Name)
{
case "columnId":
e.Value = thisPilot.id;
break;
/* Bunch of case statements... */
case "columnType":
e.Value = Enum.GetName(typeof(PilotType), thisPilot.pilot_type);
break;
}
}