Editing list properties using DataGridview
Posted
by toom
on Stack Overflow
See other posts from Stack Overflow
or by toom
Published on 2010-02-25T21:54:39Z
Indexed on
2010/05/10
15:04 UTC
Read the original article
Hit count: 305
Ok, I have my custom class:
public class FileItem : INotifyPropertyChanged
{
int id=0;
string value="";
public int Id
{
get { return id; }
set { id = value; Changed("Id"); }
}
public string Value
{
get { return value; }
set { this.value = value; Changed("Value"); }
}
public event PropertyChangedEventHandler PropertyChanged;
void Changed(string name)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
public BindingList<FileItem> FilesystemEntries = new BindingList<FileItem>();
And I have DatagridView1 with DataSource set to FilesystemEntries:
binding.DataSource = FilesystemEntries;
Already I can Add and remove rows - these chnages are reflected on collection. However, Value and Id are not saved into bidning list when i change them in DataGridView, id is always 0 and value is "".
How can I make this work? Do I need to implement some interface to FileItem to allow editing properties?
ReadOnly of DGV is set to false, same to all columns. Editing, Deleting and Changing are enabled.
© Stack Overflow or respective owner