简体   繁体   English

WinForms DataGridView-最后一行数据未显示

[英]WinForms DataGridView - Last row data not showing up

I've got a DataGridView with VirtualMode set to true, and data being supplied via the CellValueNeeded event. 我有一个VirtualGrid设置为true的DataGridView,并且通过CellValueNeeded事件提供了数据。 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. 我在设计器中设置了列,其中几个是Link列,这些列仅不显示数据。 I verified the data is in my source object (I'm binding to a IEnumerable) and that the RowCount is set correctly. 我确认数据在我的源对象中(我正在绑定到IEnumerable),并且RowCount设置正确。

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. AllowUserToAddRows 问题-设置为false。 The row is just blank, and the CellValueNeeded event doesn't appear to ever be called for that item in the IEnumerable. 该行只是空白,并且在IEnumerable中似乎从未为该项目调用CellValueNeeded事件。

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;
        }
}

And I just answered my own question... the very first line of my CellValueNeeded event is preventing the data from ever being shown. 我只是回答了我自己的问题……CellValueNeeded事件的第一行就是阻止数据显示。 Copy & paste FTW. 复制并粘贴FTW。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM