我是datagridview的新手。我有datagrid cellformatting事件。当此事件被触发时,e.Value将变为null。 如果我将数据源与Bindinglist绑定,那么如果我直接绑定IList,则e.Value为Null,我得到了正确的值。
private void Form1_Load(object sender, EventArgs e)
{
IList<MyClass> myClassList = new List<MyClass>();
myClassList.Add(new MyClass());
myClassList.Add(new MyClass());
BindingList<MyClass> myClassDS = new BindingList<MyClass>(myClassList);
var source = new BindingSource(myClassDS, null);
dataGridView1.DataSource = source; //e.Value is null here
//dataGridView.DataSource = myClassList; //This is working fine
}
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
//e.Value is null. here i should get current cell value.
}
答案 0 :(得分:0)
检查以下值:
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value