Resolved ListView or GridView can either display the data in the format I want?

tim8w

Well-known member
Joined
Sep 8, 2020
Messages
133
Programming Experience
10+
Hi,
I have data I want displayed something like this:

---------------------------------------------------------------
| 0 | ' This is the item index
---------------------------------------------------------------
| Data 1 |
---------------------------------------------------------------
| Data 2 |
---------------------------------------------------------------
| Data 3 |
---------------------------------------------------------------
| Data 4 |
---------------------------------------------------------------
| Data 5 |
---------------------------------------------------------------
| 1 | ' This is the item index
---------------------------------------------------------------
| Data 1 |
---------------------------------------------------------------
| Data 2 |
---------------------------------------------------------------
| Data 3 |
---------------------------------------------------------------
| Data 4 |
---------------------------------------------------------------
| Data 5 |
---------------------------------------------------------------

etc.

Is there anyway to accomplish this with either ListView or DataGridView controls? I'm guessing something using Groups or something like that?

I need to be able to select the Index "Row" so the user can delete the entire "Group"...

Thanks,
Tim
 
Last edited:
If you want groups then you should probably use a ListView. If you set the View to Details then you will get a grid-like layout, as is the default in Windows Explorer. The DataGridView control is highly customisable so you could certainly achieve what you want with it but it would take some effort, where the ListView will do it out of the box. You lost the ability to use data-binding with the WinForms ListView control though. A good place to start looking would be the documentation for the ListView.Groups property:

 
Generally it is frowned upon to update your UI with data directly. Ie. Don't use your UI as your data model. It's not just frowned upon, it's not recommended. That's why we use class objects with fields, properties, lists etc to form what we call models; and with those models, we can bind data to the UI. You can update the UI with a thread of by way of binding, but this would also be easier to do in WPF if you're experienced with it.

If you are sure you are receiving five items from each index. You could add them to a dictionary, and then update your UI/Control of choice with the values of the key value pair. And even if there is more than five items. Tuples have an overload you can use.

You could have a Dictionary of <int, tuple> x5.
Int would be the ID, and each tuple would be your data 1 to 5. Ex :
new Dictionary<int, Tuple<string, string, string, string, string>>();
Tuples are also great for throwing around transient data. There are many different ways to do what you are asking.

What source is your data coming from?
 
Last edited:
Thanks for the suggestion. I have decided to go back to my CustomCollectionEditor implemntation instead. Works great except that the implementation I borrowed it from is loading/saving the data to the app.Settings. I need it not to do that. I have posted that question instead.
 
Back
Top Bottom