tags:

views:

259

answers:

2

Hello,

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.

A: 

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

Tim Robinson
I cant make it that wider,the packet length is 600 bytes.So I can't do that?
John
What would you like to do with the text that's too long to fit in the column?
Tim Robinson
I'd like to make it multi line.It may be placed in two lines(items) if necessarily
John
Although it's possible to draw the list view text yourself (see the ListView.OwnerDraw property), I don't think it's possible to control the height of items: you're limited to a single line.
Tim Robinson
Maybe a full grid control would do what you need, instead of a list view? http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.aspx
Tim Robinson
+1  A: 

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!

Neil Barnwell