有人可以描述两者之间的区别对于我的项目.
目前我有一个List<MyClass>并将BindingSource设置为它,并将DataGridView设置为BindingSource.
我已经实现了IEditableObject,当调用CancelEdit时,我将我的对象恢复到它的状态Memberwise.Clone()
将我的List更改为BindingList会解决这个问题,使用BindingList有什么好处?
我似乎在圈子里跑来跑去,并且在过去的几个小时里一直这样做.
我想从一个字符串数组填充datagridview.我已经读过它不可能直接了,我需要创建一个将字符串保存为公共属性的自定义类型.所以我上了一堂课:
public class FileName
{
private string _value;
public FileName(string pValue)
{
_value = pValue;
}
public string Value
{
get
{
return _value;
}
set { _value = value; }
}
}
Run Code Online (Sandbox Code Playgroud)
这是容器类,它只是一个具有字符串值的属性.我现在想要的是当我将其数据源绑定到List时,该字符串将出现在datagridview中.
我也有这个方法,BindGrid(),我想填充datagridview.这里是:
private void BindGrid()
{
gvFilesOnServer.AutoGenerateColumns = false;
//create the column programatically
DataGridViewTextBoxColumn colFileName = new DataGridViewTextBoxColumn();
DataGridViewCell cell = new DataGridViewTextBoxCell();
colFileName.CellTemplate = cell; colFileName.Name = "Value";
colFileName.HeaderText = "File Name";
colFileName.ValueType = typeof(FileName);
//add the column to the datagridview
gvFilesOnServer.Columns.Add(colFileName);
//fill the string …Run Code Online (Sandbox Code Playgroud)