在 objectlistview 中编辑文本的正确方法是什么
What's the proper way to edit text in objectlistview
我有一个包含 4 列和动态行数的对象列表视图,我正在为可编程编辑单元格文本值而苦苦挣扎,并可选择更改前景色
我已经阅读了所有内容以及我可以动手操作的任何内容,但找不到任何有效且切题的示例来说明如何操作。
创建 ObjectListView 的原因
List<VideoItem> list = new List<VideoItem>();
foreach (dynamic item in VideoItems)
{
list.Add(new VideoItem { Index = (int)item.index, OldName = (string)item.oldname, NewName = (string)item.newname });
}
olv1.AddObjects(list);
VideoItem class 看起来像这样
private class VideoItem
{
public int Index;
public string OldName;
public string NewName;
}
but i need to programmably edit a cell text on event. I'm doing some logical operations on other cell at the end im storing the result to to cell next to it.
您应该将结果(进行更改)存储到基础模型对象,然后调用 RefreshObject(myModelObject);
About the forcolor, i need to change only the cell I've changed
"To change the formatting of an individual cell, you need to set UseCellFormatEvents to true and then listen for FormatCell events."
看看at this.
只是为了添加到 Rev1.0 答案,我需要更新包含项目的对象(在我的例子中是一个列表)然后,使用 olv1.RefreshObject(list);
流 olv1.BuildList(true);
olv1.BuildList(true);
立即刷新 GUI。
这里有一个小代码片段可以让事情更清楚
选中复选框时,它会更改第 3 列中的数据。
using System.Collections.Generic;
using System.Windows.Forms;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Initializeolv();
}
private class VideoItem
{
public int Index;
public string OldName;
public string NewName;
}
private List<VideoItem> list = new List<VideoItem>();
private void Initializeolv()
{
for (var i = 1; i <= 10; i++)
{
list.Add(new VideoItem { Index = i, OldName = $"old{i}", NewName = $"new{i}" });
}
olv1.AddObjects(list);
}
private void olv1_ItemChecked(object sender, ItemCheckedEventArgs e)
{
list[e.Item.Index].NewName = "new200";
olv1.RefreshObject(list);
olv1.BuildList(true);
}
}
}
我有一个包含 4 列和动态行数的对象列表视图,我正在为可编程编辑单元格文本值而苦苦挣扎,并可选择更改前景色
我已经阅读了所有内容以及我可以动手操作的任何内容,但找不到任何有效且切题的示例来说明如何操作。
创建 ObjectListView 的原因
List<VideoItem> list = new List<VideoItem>();
foreach (dynamic item in VideoItems)
{
list.Add(new VideoItem { Index = (int)item.index, OldName = (string)item.oldname, NewName = (string)item.newname });
}
olv1.AddObjects(list);
VideoItem class 看起来像这样
private class VideoItem
{
public int Index;
public string OldName;
public string NewName;
}
but i need to programmably edit a cell text on event. I'm doing some logical operations on other cell at the end im storing the result to to cell next to it.
您应该将结果(进行更改)存储到基础模型对象,然后调用 RefreshObject(myModelObject);
About the forcolor, i need to change only the cell I've changed
"To change the formatting of an individual cell, you need to set UseCellFormatEvents to true and then listen for FormatCell events."
看看at this.
只是为了添加到 Rev1.0 答案,我需要更新包含项目的对象(在我的例子中是一个列表)然后,使用 olv1.RefreshObject(list);
流 olv1.BuildList(true);
olv1.BuildList(true);
立即刷新 GUI。
这里有一个小代码片段可以让事情更清楚 选中复选框时,它会更改第 3 列中的数据。
using System.Collections.Generic;
using System.Windows.Forms;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Initializeolv();
}
private class VideoItem
{
public int Index;
public string OldName;
public string NewName;
}
private List<VideoItem> list = new List<VideoItem>();
private void Initializeolv()
{
for (var i = 1; i <= 10; i++)
{
list.Add(new VideoItem { Index = i, OldName = $"old{i}", NewName = $"new{i}" });
}
olv1.AddObjects(list);
}
private void olv1_ItemChecked(object sender, ItemCheckedEventArgs e)
{
list[e.Item.Index].NewName = "new200";
olv1.RefreshObject(list);
olv1.BuildList(true);
}
}
}