[英]WinForms DataGridView - Last row data not showing up
我有一個VirtualGrid設置為true的DataGridView,並且通過CellValueNeeded事件提供了數據。 一切工作正常,但是...最后一行沒有數據。 我在設計器中設置了列,其中幾個是Link列,這些列僅不顯示數據。 我確認數據在我的源對象中(我正在綁定到IEnumerable),並且RowCount設置正確。
如果我在源中添加另一行,則不會顯示該行,但是會顯示以前不可見的行。
AllowUserToAddRows 沒問題-設置為false。 該行只是空白,並且在IEnumerable中似乎從未為該項目調用CellValueNeeded事件。
我在這里拔頭發。 請幫忙。
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;
}
}
我只是回答了我自己的問題……CellValueNeeded事件的第一行就是阻止數據顯示。 復制並粘貼FTW。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.