ListViewItem text truncated after selection - Compact Framework
Asked Answered
C

5

7

I have a ListView with some ListViewItems (only text).

listView1 = new ListView
{
    View = System.Windows.Forms.View.Details,
    HeaderStyle = ColumnHeaderStyle.None
};


listView1.Columns.Add(String.Empty, -2, HorizontalAlignment.Left);

The following image is an example:

enter image description here

The problem is that when I select one of these items the text is truncated, like in the following image:

enter image description here

Why? How can I solve this problem?

Compony answered 20/3, 2013 at 16:9 Comment(5)
Could this be due to the width of the column being set to -2? Do you have a specific reason for doing that?Dandify
It may make a difference to set the ColumnHeader header; header.Width property to something else, maybe throw it in SelectionChanged{}( header.Width = listView.SelectedItem(0).Length;Microfilm
@MartinParkin -2 because I want that the column occupies all the space available (no vertical line).Compony
What version of the Compact Framework? What is the target platform (WinCE, WinMo, etc)?Zared
@Zared Compact Framework 3.5 and Windows Mobile 6.1Compony
G
1

The problem is that the Text of your ListViewItem ends with empty spaces. You have to TrimEnd the string and you have your solution.

Goodman answered 11/4, 2013 at 18:55 Comment(0)
M
0

It may make a difference to set:

ColumnHeader header; 

then, the header.Width property to something else, maybe throw it in

SelectionChanged{}(  
    header.Width = listView.SelectedItem(0).Length;
)

Give it a shot. I'm just thinking that the header / column width is playing tricks with how it's defaulted, or potentially set by you with the -2

This link may help with ColumnHeaders: MSDN ColumnHeaders


EDIT:

So I have reviewed some of the CompactFramework stuff.

This Link seems to be relevant to the same issue.

Try setting your ColumnWidth property to -1

listView1.Columns.Add(String.Empty, -1, HorizontalAlignment.Left);

That should set it to the widest value in the column. I do see the -2 options should work, but try -1, just to see if it makes a difference.

Double Edit:

Our comments have been moved into a Chat / Discussion, although we have been unable to figure out what is causing this. If anyone has suggestions or knows a fix, please inform us!

Microfilm answered 20/3, 2013 at 16:23 Comment(7)
Oh, noooo! Hrm, that's a shame, I'll see if I can find anything else, should have realized it was for the Compact.Microfilm
Unfortunately it does not change anything, I have only one more vertical line (that i don't want to see).Compony
When are the columns being set? Are they being set at RunTime, or afterwards? It sounds like the compiler is setting them at the wrong time, either before they are needed, then the data is placed and it's not being resized, or after RunTime and the columns are initialized at a fixed size (the default, as no values are added yet), then the values get added, but the size is remaining the same.Microfilm
AND! Are you initializing these with String.Empty? That may be why these guys are still staying fixed in size, as the ColumnWidth is staying at the size of String.Empty, as that's what it was initially set at.Microfilm
I add the column in the constructor of the UserControl that contains the ListView. The header of the column is an empty string.Compony
Gotcha, that sounds like it should do the trick, as the constructor will, well, construct... Have you tried setting String.Empty to Imagine? I understand that you want your Columns to be added dynamically, on a need basis, but what I'm thinking is that the String.Empty is what's interfering. Check what happens when you hardwire the column that is having trouble in. If it doesn't truncate it when it's selected, it's the String.EmptyMicrofilm
let us continue this discussion in chatMicrofilm
Z
0

Use this column size logic instead:

listView1.Columns[0].Width = listView1.Width;
Zared answered 20/3, 2013 at 16:56 Comment(2)
Please let us know if this works! And if you have any idea why this fixes it :]Microfilm
I doesn't work. I don't know why but my listView1.Columns[0].Width is 460 in the SelectionChanged event (instead of -2). My listView1.Width is 464, so if I add this code in the event i can see the horizzontal scroll bar, but the text is still truncated.Compony
P
0

You should be able to change manually the width of the column. Go in designer mode and change it manually. Just drag it

Pico answered 8/4, 2013 at 15:37 Comment(1)
The problem is not the column width (that is always the same).Compony
F
0

Can you check Selected item style . . .
The selected item Textwrapping="Wrap" or Increasing selected item column width. I think only problem with this two.

Foundation answered 9/4, 2013 at 10:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.