1
我有一個VirtualMode設置爲true的DataGridView,並通過CellValueNeeded事件提供數據。一切正常,但是......最後一行沒有數據。我在設計器中設置了列,其中有幾個是鏈接列,那些列顯示沒有數據。我驗證了數據在我的源對象中(我綁定到IEnumerable)並且RowCount設置正確。WinForms DataGridView - 最後一行數據沒有顯示
如果我向源添加另一行,它不會顯示,但之前不可見的那個會顯示出來。
這是不是 AllowUserToAddRows的問題 - 它設置爲false。該行只是空白,CellValueNeeded事件似乎永遠不會被IEnumerable中的該項調用。
我在這裏拉我的頭髮。請幫忙。
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;
}
}