Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, I have following list:
C#
this.list.Size = new System.Drawing.Size(200, 200);
this.list.HeaderStyle = ColumnHeaderStyle.None;
this.list.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.list.GridLines = true;
this.list.MouseUp += new MouseEventHandler(list_MouseUp);

And I need to dynamically change content of this list and change row count as well:
C#
public List<ListViewItem> Settings
{
    get
    {
         return settings;
    }
    set
    {
         settings = value;
         this.list.Items.Clear();
         this.list.Items.AddRange(value.ToArray());
         //this.list.Bounds = new Rectangle(list.Location.X, list.Location.Y, 200, 18 * value.Count);
         //this.list.Size = new System.Drawing.Size(200, 18 * value.Count);
         //this.list.Invalidate();
    }
}


But after changing Size of list (or Bounds), the list_MouseUp event fires only when value.Count > 1.

// Or, how to dynamically adjust count of displayed rows?

Any help?
Posted
Updated 18-Jun-13 2:26am
v2
Comments
Sergey Alexandrovich Kryukov 18-Jun-13 8:37am    
You need to tag UI library or application type. In other words, what is the full type name of ListView?
—SA
patrik polakovic 18-Jun-13 8:48am    
Inherited from System.Windows.Forms.ListView.
I am using technique described in this example: http://support.microsoft.com/kb/320344 to add my own UI components.
Sergey Alexandrovich Kryukov 18-Jun-13 8:58am    
Do you do "this.list.MouseUp += ..." only once? In all cases, the handler should be called. Why do you think otherwise? Put a breakpoint and use the debugger to make sure.
—SA
johannesnestler 18-Jun-13 9:09am    
So you have a List of ListViewItems objects which when (re-)assigned (hopfully not null, or code will crash) should be added to a ListView control. Quite obscure way for me to solve this. But anyway, what you want is to change the size of the listview depending on it's items count? (btw. you can use GetItemRect to get the bounding rectangle for one item, hardcoding "18" is maybe "not so good")? I don't ask why you want to do this - but how many listview's have you seen and how many of them behaved like this? So, you say after changing the size in any way leads to non-firing MouseUp events? Is this all correct?
BillWoodruff 18-Jun-13 9:40am    
Is your actual goal here to have a ListView that automatically changes its height depending on how many ListViewItems it has ? If "yes," how are new ListViewItems added at run-time, or deleted ?

Compared to the Microsoft example you cite in response to SAK: the MS example is using a ComboBox and a ListView: when a row in the ListView is clicked, the ComboBox is made visible, and has focus: its position and size set to display it over the selected ListViewItem. The purpose of the ComboBox is to allow you to edit the ListViewItem values, selecting from a pre-defined set of values.

Your commented out code shows that you are changing the size of a ListView.

The MS example is very old code; fyi: it's a Component, not a UserControl, and, it's a terrible example.

Describe your goal clearly, and you'll get clearer responses.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900