views:

241

answers:

1

Hello everyone,

Working in C# win forms, I'm trying to create a list of items where each item is compromised of an icon and 3 labels in a specific layout.

Here's an illustration of it (http://hosting04.imagecross.com/image-hosting-13/3535help.jpg):

The user should be able to select a single row, just like in a normal Listview.

My first attempt was creating the icon and labels in a user control, and then putting the user control in a FlowLayoutPanel in a vertical layout (which would create a list). The problem was the selection. Since the clicking event was captured by the user control, there was no easy way on letting the other user controls in the list know that the control was selected and if they are currently selected they now should be unselected. (I hope this makes sense...)

I also tried using some open source custom Listview I found here: http://www.codeproject.com/KB/list/aa_listview.aspx but it's too buggy.

I also thought about creating a custom control that will inherit from Listview and render my user control in the list, but I also read about someone who tried to do that and got into a lot of difficulties.

I'd be very happy to hear any suggestions you might have.

Thanks!

A: 

What you may want to try is have two user controls. One control which you seem to already have, which is the icon and the labels. This will be an internal control that you can't instantiate outside of your assembly. The second user control, will just be a container of sorts (you can do this either by actually using a user control, or inheriting from a panel or whatever, doesn't matter). This will just serve as a collection of the individual items, and it will manage the selecting and unselecting of the items.

Basically, each user control will raise the click event, which your container user control will hook up to. It will then know which to select, and which to unselect.

Hope that makes sense!

BFree