【发布时间】:2014-12-30 22:42:28
【问题描述】:
我在尝试使用 BindingList 类型的数据源向 Infragistic UltraWinGrid 添加新行时遇到以下错误:
无法添加行:找不到类型“System.String”的构造函数
通过网格删除项目可以正常工作,但是在尝试使用网格底部的添加新行时会出现上述错误。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win;
namespace BindingListChangedEvent
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
private BindingList<string> shoppingList;
private void FrmMain_Load(object sender, EventArgs e)
{
//let's just add some items to the list
string[] items = { "Rice", "Milk", "Asparagus", "Olive Oil", "Tomatoes", "Bread" };
shoppingList = new BindingList<string>(items.ToList());
shoppingList.AllowNew = true; //if this is not set error: "Unable to add a row: Row insertion not supported by this data source" is thrown
ugList.DataSource = shoppingList;
shoppingList.ListChanged += new ListChangedEventHandler(ShoppingList_ListChanged);
}
public void ShoppingList_ListChanged(object sender, ListChangedEventArgs e)
{
MessageBox.Show(e.ListChangedType.ToString()); //what happened to the list?
}
private void ugList_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
e.Layout.Override.CellClickAction = CellClickAction.RowSelect;
e.Layout.Override.AllowDelete = DefaultableBoolean.True;
e.Layout.Override.AllowAddNew = AllowAddNew.TemplateOnBottom;
}
private void btnAddCookies_Click(object sender, EventArgs e)
{
shoppingList.Add("Cookies");
ugList.Refresh();
}
}
我尝试在不涉及 UltraWinGrid (btnAddCookies_Click) 的情况下添加一个按钮以手动将项目添加到列表中,这没有问题。
有什么想法可以帮助我朝着正确的方向前进吗?谢谢
【问题讨论】:
标签: c# winforms infragistics