Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline Text In List View

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 .

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

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" }));
}

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

Anybody has idea ? TNX.

like image 867
user3290286 Avatar asked Feb 28 '14 19:02

user3290286


1 Answers

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" });
}

Result:

enter image description here

like image 67
LarsTech Avatar answered Oct 11 '22 18:10

LarsTech