列表视图项目不显示

发布于 2024-11-09 13:22:13 字数 958 浏览 0 评论 0原文

是否有原因,当使用 listview1.View = View.Details 时,当我添加项目但让它们不可见时,我的列表视图会展开(生成滚动条),但是当我将其切换到 listview1 时,我的列表视图会展开(生成滚动条) .View = View.List 它工作得很好吗?

并不是说我认为这真的很重要,但这是我用来向列表视图添加项目的代码:

     ListViewItem item1 = new ListViewItem(file[1]);
     listView1.Items.Add(item1);

自动生成的设计器代码:

        // 
        // listView1
        // 
        this.listView1.CheckBoxes = true;
        this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
        this.Path});
        this.listView1.Location = new System.Drawing.Point(12, 44);
        this.listView1.Name = "listView1";
        this.listView1.Size = new System.Drawing.Size(457, 354);
        this.listView1.TabIndex = 7;
        this.listView1.UseCompatibleStateImageBehavior = false;
        this.listView1.View = System.Windows.Forms.View.Details;

file 是一个字符串数组,第一个元素中包含大约 50 个奇数字符(使用调试器检查) 。

Is there a reason why when using listview1.View = View.Details my listview will expand (generate scrollbars) when I add items but have them be invisible, but when I switch it over to listview1.View = View.List it works just fine?

Not that I think that it really matters, but here is the code that I use to add items to the listview:

     ListViewItem item1 = new ListViewItem(file[1]);
     listView1.Items.Add(item1);

And the autogenerated designer code:

        // 
        // listView1
        // 
        this.listView1.CheckBoxes = true;
        this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
        this.Path});
        this.listView1.Location = new System.Drawing.Point(12, 44);
        this.listView1.Name = "listView1";
        this.listView1.Size = new System.Drawing.Size(457, 354);
        this.listView1.TabIndex = 7;
        this.listView1.UseCompatibleStateImageBehavior = false;
        this.listView1.View = System.Windows.Forms.View.Details;

file is a string array that contains about 50 odd characters in the first element (checked using debugger).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

七七 2024-11-16 13:22:13

你在叫“清除”吗?如果是这样,请确保您调用的是 lv.Items.Clear() 而不是 lv.Clear()

Are you calling "Clear"? If so make sure you are calling lv.Items.Clear() and not lv.Clear().

过度放纵 2024-11-16 13:22:13

下面的代码应该可以工作:

ColumnHeader columnHeader1=new ColumnHeader();
columnHeader1.Text="Column1";
this.listView1.Columns.AddRange(new ColumnHeader[] { columnHeader1 });
ListViewItem item = new ListViewItem("1");
this.listView1.Items.Add(item);
this.listView1.View = View.Details;

如果没有,我就不知道了。您添加的字符串的字符是否可见?

The following code should work:

ColumnHeader columnHeader1=new ColumnHeader();
columnHeader1.Text="Column1";
this.listView1.Columns.AddRange(new ColumnHeader[] { columnHeader1 });
ListViewItem item = new ListViewItem("1");
this.listView1.Items.Add(item);
this.listView1.View = View.Details;

If it doesn't I have no clue. Are the characters of the string you are adding visible?

放我走吧 2024-11-16 13:22:13

您需要添加一列才能使详细信息视图正常工作。

You need to add a column for Details view to work.

水染的天色ゝ 2024-11-16 13:22:13

我遇到了同样的问题,在我的 listview 中看不到文本。当我使用代码克隆该项目时,该错误是我犯的;我不小心只重命名了第一部分,并再次将文本信息添加到第一个项目中,而不是克隆的项目中。我的意思是:

错误:

ListViewItem item_klon2 = new ListViewItem();
item_klon.Text = System.IO.Path.GetFileName(file_with_path);
item_klon.SubItems.Add(short_date);
item_klon.SubItems.Add(filesize.ToString() + " kb");

正确:

ListViewItem item_klon2 = new ListViewItem();
item_klon2.Text = System.IO.Path.GetFileName(file_with_path);
item_klon2.SubItems.Add(short_date);
item_klon2.SubItems.Add(filesize.ToString() + " kb");

I had the same problem, with not visible text in my listview. The error was made by me, when I cloned the item using code; I accidentally renamed only the first part and added text information again to the first items but not the cloned items. Here is what I mean:

Wrong:

ListViewItem item_klon2 = new ListViewItem();
item_klon.Text = System.IO.Path.GetFileName(file_with_path);
item_klon.SubItems.Add(short_date);
item_klon.SubItems.Add(filesize.ToString() + " kb");

Right:

ListViewItem item_klon2 = new ListViewItem();
item_klon2.Text = System.IO.Path.GetFileName(file_with_path);
item_klon2.SubItems.Add(short_date);
item_klon2.SubItems.Add(filesize.ToString() + " kb");
丿*梦醉红颜 2024-11-16 13:22:13

我也有同样的问题。

我已将列宽设置为 -2,以便它自动调整大小以适应列标题中文本的长度。当我切换到“详细信息”视图时,列宽自动重置为 0,从而隐藏了项目。

I had the same problem.

I had set the column width to -2 so it would auto size to the length of the text in the column header. When I switched to Details view the column width was automatically reset to 0, thereby hiding the items.

像极了他 2024-11-16 13:22:13

只需将其添加到您的列表视图中即可。更改 listview1 你的列表视图名称:

listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left);

Just add that to your Listview. Change listview1 your Listview name:

listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文