0
我有一個窗口的形式和具有在其上一個GridView,與下列屬性C#從事件
沿如果在形式初始化I型
myGridView1.Columns.Add("ColumnName", "ColumnHeaderText");
更新的GridView列加載窗體時我看到我的GridView上的列,但是如果我在ListChanged事件中鍵入相同的代碼,我沒有看到GridView上的列 爲什麼會發生這種情況?
private void _browseLayoutColumns_ListChanged(BrowseLayoutColumns item)
{
myGridView1.Columns.Add("ColumnName", "ColumnHeaderText");
}
private MyList<BrowseLayoutColumns> _browseLayoutColumns = new MyList<BrowseLayoutColumns>();
public MyList<BrowseLayoutColumns> BrowseLayoutColumns
{
get
{
return _browseLayoutColumns;
}
set
{
if(value == null) return;
_browseLayoutColumns = value;
}
}
MYLIST和BrowseLayoutColumns實現是以下:
public class BrowseLayoutColumns
{
#region Properties
private string _columnName = string.Empty;
public string ColumnName
{
get => _columnName;
set
{
if (null == value) return;
_columnName = value;
}
}
private string _bindingField = string.Empty;
public string BindingField
{
get => _bindingField;
set
{
if (null == value) return;
_bindingField = value;
}
}
#endregion
}
internal class MyList<T> : List<T> where T : class
{
#region ListMethods
public new void Add(T item)
{
base.Add(item);
ListChanged?.Invoke();
}
public new void Clear()
{
base.Clear();
ListChanged?.Invoke();
}
#endregion
#region Events
public event ListChangedEventHandler ListChanged;
public delegate void ListChangedEventHandler();
#endregion
}