我的一些课 的成员不会出现绑定到BindingList的datagridview

问题描述 投票:0回答:1
public class ANote{
    public string NoteId = "";
    public string Note = "";
    public string NoteCollector = "";
    public DateTime NoteCollectionDate = DateTime.MinValue;
    public string NoteCollectionDay {
    get { return NoteCollectionDate.toString("MM/dd/yyyy") ; }
    }
    public string NoteCollectionTime {
    get { return return NoteCollectionDate.toString("hh/mm tt"); }
    }
    public DateTime ADate = DateTime.Now;
    public double AAmount = 0.0D;
    public string AName = "";
    }

和BindingList aList;

还有一个网格与一堆DataGridTExtBoxColumns,我试图绑定到上面(已填充)列表,如:

colDate.DataPropertyName ="NoteCollectionDay";
colTime.DataPropertyName = "NoteCollectionTime";
colName.DataPropertyName = "NoteCollector";
colADate.DataPropertyName = "ADate";
colAAmount.DataPropertyName = "AAmount";
colAName.DataPropertyName = "AName";
colNotes.DataPropertyName = "Note";

grdNotes.AutoGenerateColumns = false;
grdNotes.DataSource = aList;

但在运行时,只有我的colDate和colTime列正确填充。所有其他人都是空白的。当我特别注意其他colmns的Grid.Rows[idx].Cells[idx].Value时,它全部为空。

此外,如果我将AutoGenerateColumns设置为true,我会看到一个额外的列NoteID,并且也正确填充,但ANote,Amount,ADate,AName和Note字段仍为空白!

列表中的数据没有任何问题..所有类成员都有有效值。

除非我遗漏了某些东西它似乎是BindingList或DataGridView的一个问题..如果没有,关于如何调试this..it的任何想法都是一个非常简单的测试用例!

c# datagridview bindinglist
1个回答
4
投票

您指的是DataPropertyName,因此只有属性可以使用?

其余的都是田地。尝试将它们转换为自动属性:

public string Note { get; set; }

另请注意,BindingList只会通知订阅者列表本身的内容已更改,而不是列表中包含的对象的属性。

如果要实现此目的,您希望对象实现INotifyPropertyChanged,并在属性的set方法中触发通知。

© www.soinside.com 2019 - 2024. All rights reserved.