多行文字在列表视图中 [英] Multiline Text In List View

查看:181
本文介绍了多行文字在列表视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尽量让一个WinForm包含的ListView为详细信息(ListView1.View =详细资料)
这ListView中有2子项,我需要总结的字符串,并把它分项。

I try to make a winform contains the ListView as Details (ListView1.View = "Details") This ListView has 2 SubItems and i need to Wrap String and put it to SubItem .

我不能使用其他像TableXP或...创建的任何组件或用户控件

I can not use any component or user control that created by other Like TableXP or ...

编辑:
我用这个code:

I Use this Code :

lstShares.Columns.Add("Share Name",100);
                lstShares.Columns.Add("Path",300);
                lstShares.View = View.Details;
                ManagementObjectSearcher shares = new ManagementObjectSearcher("Select * from Win32_Share");
                foreach (ManagementObject share in shares.Get())
                {
                    lstShares.Items.Add(new ListViewItem(new String[] { share["Name"].ToString(), share["Path"].ToString() + "\n" + "AAAA" }));
                }

如果我用\\ n或Environment.NewLine什么不改变像下面的图片

If I use "\n" or Environment.NewLine anything don't change like below picture

任何人有想法?
TNX。

Anybody has idea ? TNX.

推荐答案

考虑使用DataGridView控件来代替。它支持包装:

Consider using the DataGridView control instead. It supports wrapping:

dgv.AutoGenerateColumns = false;
dgv.RowHeadersVisible = false;
dgv.MultiSelect = false;
dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dgv.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dgv.Columns.Add(new DataGridViewTextBoxColumn() {
  HeaderText = "Share Name",
  ReadOnly = true,
  AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill,
  FillWeight = 25
});
dgv.Columns.Add(new DataGridViewTextBoxColumn() {
  HeaderText = "Path",
  ReadOnly = true,
  AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill,
  FillWeight = 75
});
var shares = new ManagementObjectSearcher("Select * from Win32_Share");
foreach (ManagementObject share in shares.Get()) {
  dgv.Rows.Add(new String[] { share["Name"].ToString(),
                              share["Path"].ToString() + "\n" + "AAAA" });
}

结果:

这篇关于多行文字在列表视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆