2

BindingListでのDataGridViewの使用に関して、現在の行の編集を無効にしましたが、新しい行の追加は許可しました。私が抱えている問題は、編集を許可しない場合、この新しい行のセルにテーブルを作成すると編集が許可されないように見えるため、新しい行アイテムを追加できないように見えることです。

これを回避する方法を知っていますか?以下の私のコードのセクション:

   BindingSource bs = new BindingSource();
   bList = new BindingList<Customer>();
   bList.AllowNew = true;
   bList.AllowEdit = false;

   // Fill bList with Customers
   bList.Add(new Customer("Ted"));
   bList.Add(new Customer("Greg"));
   bList.Add(new Customer("John"));

   bs.DataSource = bList;
   dataGridView1.DataSource = bs;

ありがとう

4

1 に答える 1

4

ソースと戦うのではなく、おそらく司祭に依頼してくださいDataGridView

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

(そしてリストに設定しないでくださいAllowEdit

于 2009-10-05T11:33:25.200 に答える