【发布时间】:2012-04-17 12:58:54
【问题描述】:
我正在动态创建 ListViewItem 后代:
class Application : ListViewItem {
. . .
class LegacyApplication : Application {
我首先将这些存储在一个对象列表中:
private List<object> legacyApps = new List<object>();
..这样:
if (ldbc.appIsLegacy(sPathOfExe)) {
legacyApp = new LegacyApplication(sApp, sTitle, sDesc, sIconFileName, sPathOfExe, appCategoriesForCurrentApp);
}
legacyApps.Add(legacyApp);
...然后我以这种方式将它们添加到主窗体上的 ListView 中:
foreach (LegacyApplication LegApp in legacyApps) {
this.listApplications.Items.Add(LegApp);
}
...但 ListView 不显示它们。它显示了我创建的 ListView 组(并且每个 ListViewItem 都分配给这些组之一),但不显示 ListViewItem 本身...
更新了请求的信息:
ListViewItem 后代的构造函数如下所示:
public LegacyApplication(String AAppName, String ATitle, String ADesc, String AIconFileName, String APathOfExe, List<String> ACategories) {
base.Name = String.Format("legapplvi{0}", AAppName);
base.Text = ATitle; // "Title" is a short description - between exe name and Description
base.ToolTipText = ADesc;
base.EnsureVisible();
// "base" above means ListViewItem; "base" below refers to our Application class*
base.Categories = ACategories;
base.ExePath = APathOfExe;
base.IconFileName = AIconFileName;
}
- 将以下属性添加到 ListViewItem:
公共字符串 ExePath 公共字符串 IconFileName 公共字符串类别 公开列表类别
LegacyApplication 没有向(我们的)Application 类添加更多属性。
我不确定下面的受访者所说的“子项”是什么意思 - ListViewItems 是 ListView 组的子项,也许...?
更新了未经请求的信息(TMI?):
好的,我想我可以通过这种方式添加列,一旦所有组都分配给 ListView:
for(var item in listApplications.Groups) {
listApplications.Columns.Add(item)
}
...但是现在,如何将特定的 ListViewItems 添加到特定列?
在(某种)工作后更新:
注释掉这个:
listApplications.View = View.Details;
...获取要显示的项目。但是,文本被截断,这导致我在这里提出另一个问题:
I need to display the entire Text of my ListViewItems (not truncated)
【问题讨论】:
-
您能否提供更多关于您如何在子类 ListViewItem 中的 ListViewItem 中设置 Text 和 SubItems 的详细信息?另外,您的 ListView 的属性是什么?
-
如果您使用 View = Details,请不要忘记添加 ColumnHeaders。没有任何您将看不到添加的项目。
-
我指的是子项,因为我(错误地)假设您使用的是详细信息显示模式。我没有立即发现您提供的内容有任何明显错误,抱歉。
-
你还能为你的 ListView 添加一个 Xaml 吗?我很好奇是这些团体
-
看来你有两件事在这里发生,我没有看到任何显示默认 ListView 控件的继承。我最初的反应是从一个“常规”aspx 页面开始,直接在页面上使用 ListView 控件,并使用模板绑定来清除您的问题……然后将其提取到控件中,确保从 ListView 控件继承.
标签: c# .net listview dynamic listviewitem