C# WinForms BindingList & DataGridView - disallowing EDIT prevents creation of a NEW row? How can I address this?

后端 未结 1 822
南方客
南方客 2021-01-22 20:00

Regarding my use of a DataGridView with BindingList, I was to disable editing current rows, but allow adding new rows. The issue I have is that when I disallows edits, this see

1条回答
  •  盖世英雄少女心
    2021-01-22 20:06

    Rather than fight the source, perhaps ask the DataGridView to officiate:

    dataGridView1.DataSource = bs;
    dataGridView1.ReadOnly = true;
    dataGridView1.CurrentCellChanged += delegate 
    {
        DataGridViewRow row = dataGridView1.CurrentRow;
        bool readOnly = row == null ||
            row.Index != dataGridView1.NewRowIndex;
        dataGridView1.ReadOnly = readOnly;
    };
    

    (and don't set AllowEdit on the list)

    0 讨论(0)
提交回复
热议问题