Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

c# Listview subitem text wrap

Status
Not open for further replies.

drey8

Programmer
Aug 31, 2004
17
US
Does any one know how to wrap the text in a subitem? I have a list view with one subitem, which is a description of the item, sometimes it would be 3 to 4 lines. I would like all the text to show in the listview.

thank you for your help
drey
 
You could create a single string out of those multiple lines and display it that way. I don't believe the ListViewItem supports multiple line display.

You might be able to find a custom ListView that will do multiline or you could write your own.

I know the DataGrid can be hacked to allow things like progress bars, buttons, and custom controls to be added but they are a pain to deal with.

If you find a control that does multiline - let me know!
 
Hello!
I sort of found a easy solution.
Create a ListViewBox (i created with name lstScenarioDesc)and then copy this code and call it from page_load,
private void CreateMyListView()
{

// Set the view to show details.
lstScenarioDesc.View = View.Details;
// Allow the user to edit item text.
lstScenarioDesc.LabelEdit = true;
lstScenarioDesc.LabelWrap = true;
// Allow the user to rearrange columns.
lstScenarioDesc.AllowColumnReorder = true;
// Select the item and subitems when selection is made.
lstScenarioDesc.FullRowSelect = true;
// Display grid lines.
lstScenarioDesc.GridLines = true;

// Create columns for the items and subitems.
lstScenarioDesc.Columns.Add("Column 1", 100, HorizontalAlignment.Left);
lstScenarioDesc.Columns.Add("Column 2", 200, HorizontalAlignment.Left);

ListViewItem listItem1 = new ListViewItem("CPU");
ListViewItem listItem2 = new ListViewItem("");
ListViewItem listItem3 = new ListViewItem("");
listItem1.SubItems.Add(new ListViewItem.ListViewSubItem(
listItem1, "Something longer so it does not fit "));
listItem2.SubItems.Add(new ListViewItem.ListViewSubItem(
listItem2, "in one line.So I am trying."));
listItem3.SubItems.Add(new ListViewItem.ListViewSubItem(
listItem3, "And so multi line works sort off"));
lstScenarioDesc.Items.Add(listItem1);
lstScenarioDesc.Items.Add(listItem2);
lstScenarioDesc.Items.Add(listItem3);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top