我在演示项目中尝试了演示代码,但无法成功地添加新项目。它只添加新的空组和空项。请给我一个简单的例子代码,以添加新的项目(文本和图像)。
谢谢!
哦对不起!我忘了。这是我第一次参加这个网站。我用C#。守则是:
objectListView1.BeginUpdate();
objectListView1.AddObject(new string [] {"Hello","dfdsF" });
objectListView1.EndUpdate();和
objectListView1.BeginUpdate();
OLVListItem item = new OLVListItem(new string [] {"Hello","dfdsF" });
objectListView1.Items.Add(item);
objectListView1.EndUpdate();它与ListView和EXListView非常不同,我可以在创建新项时定义文本或图像。但是在ObjectListView中,我不明白对象是什么?
我得到了ObjectListView,这里是演示代码,http://nchc.dl.sourceforge.net/project/objectlistview/objectlistview/v2.5/ObjectListViewFull-2.5.0.zip
发布于 2012-02-28 13:57:26
我将向您展示如何添加项目。尝试创建一个类,然后为要在ObjectListView上显示的属性创建getter和setter。
SetObjects方法采用List<T>
public Form1()
{
InitializeComponent();
this.objectListView1.SetObjects(haha.GET());
}这是我的类,我叫它haha,其中有两个属性(Name和Detail):
class haha
{
string name;
string detail;
public haha(string name , string detail)
{
this.name = name;
this.detail = detail;
}
public string Name
{
get { return name; }
set { name = value; }
}
public string Detail
{
get { return detail; }
set { detail = value; }
}
static internal List<haha> GET()
{
haha item = new haha("zeko", "dunno");
haha xx = new haha("sheshe", "dunno");
haha ww = new haha("murhaf", "dunno");
haha qq = new haha("soz", "dunno");
haha ee = new haha("HELLO", "dunno");
List<haha> x = new List<haha>();
x.Add(item);
x.Add(xx);
x.Add(ww);
x.Add(qq);
x.Add(ee);
return x;
}
}现在
ObjectListView中的ShowGroups更改为falseName,另一列用于AspectName,并写入您希望从类F 220中显示的属性的名称。

结果如下:

如果您想使用AddObject(),它接受一个对象,我会这样写:
private void button1_Click(object sender, EventArgs e)
{
haha newObject = new haha("memo","zezo");
objectListView1.AddObject(newObject);
}快乐编码:)
发布于 2013-02-06 22:00:30
最好是使用实体类。然后列出一个项目列表并将这个列表添加到您的ObjectListView中。
myObjectListView.SetObjects(myListofEntityItems);但在这样做之前,您必须在设计器中设置列。只要添加一个列,AspectName就可以在字段中输入实体项的属性的确切名称。
https://stackoverflow.com/questions/7949887
复制相似问题