Ivan Prodanov
Ivan Prodanov

Reputation: 35532

How to add large text to listview's(detailed) items?

I'm writing an analyzer,which shows the packets of a specific program.Some packets are very large and the listview shows only the first 15-20 characters :\

This is my code

        string __str = String.Join(" ", data.Select(x => x.ToString("x2")).ToArray()); //covert the byte[](packet) to hex string
        string __ascii = AsciiToString(data); //convert the byte[](packet) to ASCII
        if (encrypted) FormMain.PFA(form => form.listViewAnalyzer.Items.Add("S<-C [ENCRYPTED] Blowfishkey = 0xFF")); 
        else FormMain.PFA(form => form.listViewAnalyzer.Items.Add("S<-C")); 
        ListViewItem item = new ListViewItem(__str); //create new item and place the packet as hex string
        item.SubItems.Add(__ascii); //add the ascii variant as substring
        FormMain.PFA(form => form.listViewAnalyzer.Items.Add(item)); //add the item

It must be a property that prohibits adding text with more than x lines,but I can't see it.

Upvotes: 0

Views: 1383

Answers (2)

Neil Barnwell
Neil Barnwell

Reputation: 42165

The listview will contain all the text, you just can't see it if it's too long or has multiple lines.

The way that Outlook and things like packet sniffers often work is that the listview is accompanied by a textbox or "preview" window. You could change your UI so that selecting the item in the listview displays the full details of the item in an outlook-style preview pane. Then you could have a large multiline textbox and anything else you wanted. I often do this by putting an object in the ListViewItem.Tag property, so that I can retrieve it in the UI and display in the preview when the ListView.SelectedIndexChanged event fires.

Alternatively, the preview could be on a dialog that pops up when you double-click. In fact, make the preview UI a UserControl, then you can do both!

Upvotes: 1

Tim Robinson
Tim Robinson

Reputation: 54764

listview shows only the first 15-20 characters :\

Maybe you need to make the column wider?

It must be a property that prohibits adding text with more than x lines,but I can't see it.

List view items don't wrap text, so technically they prohibit text with more than 1 line

Upvotes: 0

Related Questions