C#的WinForms的BindingList和放大器; DataGridView的 - 不允许编辑防止新行的创造?我怎样才能解决这个问题? [英] C# WinForms BindingList & DataGridView - disallowing EDIT prevents creation of a NEW row? How can I address this?

查看:240
本文介绍了C#的WinForms的BindingList和放大器; DataGridView的 - 不允许编辑防止新行的创造?我怎样才能解决这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的使用具有的BindingList DataGridView的,我是禁用编辑当前行,但允许添加新行。我的问题是,当我不允许修改,这似乎是阻止人们加入一个新的行项目,因为当你似乎进入表为这个新行的单元格不会让编辑???

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 seems to prevent one from adding a new row item, as when you table into the cell for this new row it does not seem to allow editing???

知道如何解决这个问题?下面我的代码部分:

Know how to get around this? Section of my code below:

   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;



感谢

thanks

推荐答案

而不是对抗的根源,也许问 DataGridView的来主持:

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;
};



(不要设置 AllowEdit 上名单)

这篇关于C#的WinForms的BindingList和放大器; DataGridView的 - 不允许编辑防止新行的创造?我怎样才能解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆