- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个 DataGridView
与 DataSource
设置为 List<myClass>
但是,当我设置 AllowUserToAddRows
时,新行指示器不显示至 true
,
当我设置 DataSource
至 BindingList<myClass>
,这似乎解决了问题。
问:应该替换我的 List<>
与 BindingList<>
或者有更好的解决方案?
最佳答案
是否 myClass
有一个公共(public)的无参数构造函数?如果不是,您可以从 BindingList<T>
派生并覆盖 AddNewCore
调用您的自定义构造函数。
(edit) 或者 - 只需将您的列表包装在 BindingSource
中它可能会起作用:
using System;
using System.Windows.Forms;
using System.Collections.Generic;
public class Person {
public string Name { get; set; }
[STAThread]
static void Main() {
var people = new List<Person> { new Person { Name = "Fred" } };
BindingSource bs = new BindingSource();
bs.DataSource = people;
Application.Run(new Form { Controls = { new DataGridView {
Dock = DockStyle.Fill, DataSource = bs } } });
}
}
关于c# - AllowUserToAddRows 不适用于 DataGridView 上的 List<> 数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1565875/
我有一个使用 Entity Framework 的简单项目,我的 Form 中有一个 DataGridView 并将其 AllowUserToAddRow 属性设置为 true 但我仍然无法向其中添加
我原以为此设置会影响控件本身,但我似乎无法通过将 AllowUserToAddRows 设置为 true 的 DataGridView 添加新行。我只是在使用我的鼠标和键盘垃圾,还是我完全误解了这个属
我有一个 DataGridView与 DataSource设置为 List 但是,当我设置 AllowUserToAddRows 时,新行指示器不显示至 true , 当我设置 DataSource至
我是一名优秀的程序员,十分优秀!