views:

67

answers:

2

Is it possible to create ListView in C# (in Details View) just like in MS Access where when you can show in ListView things that are connected with particular item by some ID so you can clearly see those items are binded together. Currently I'm using colors so that when 3 items in same table are connected with same ID they are marked with one color, if next item has different ID then it has other color. This is ok solution but would prefer some clearer way.

 if (lastnumber != varOplatyLacznikID) {
    lastnumber = varOplatyLacznikID;
    lastcolor = lastcolor == Color.LightBlue ? Color.LightCyan : Color.LightBlue;
 }

I would like it to be displayed like this (more or less)

ITEM1 | VALUE1 | VALUE5
+ ITEM3 | VALUE1 | VALUE7
+ ITEM4 | VALUE1 | VALUE8
ITEM5 | VALUE2 | VALUE9

Normally it would display ITEM1 and ITEM5 but when i would click + sign next to ITEM1 it would show ITEM3 and ITEM4. It looks very nice in MS Access and would like to copy this functionality if it's not too much work.

Using ObjectListView is not in scope since I don't want to rebuild a lot of code to implement this functionality. I'm looking for a way to just extend what I've got.

A: 

Here's a blog post by Matt Berseth that does this.

klabranche
That example uses a ListView inside of a ListView. I think @MadBoy wants a ListView inside of a DetailsView, but based on his desired display that might not be true...
Abe Miessler
Good point. It's close then... :-)
klabranche
This is grouping, it sounds like a possible solution (although example is asp.net and i need WinForms) but i would want it ti display item just like normal item with lots of subcolumns, but when you click on + next to it it expands showing additional items below it. Kinda like grouping but with group being actual ListView Item with subcolumns.
MadBoy
Oooppppsss... I didn't notice the winforms tag.... Sorry about that.
klabranche
A: 

Have you tried just using a TreeView? This would work if it's not absolutely necessary that the columns line up perfectly. Or you could use a fixed-width font and use Format() to make a string that contains fixed-width fields so that they do line up. It's a quick hack if you don't want to actually go to the trouble of making true expandable lists.

Reinderien
I don't want to use treeView. I thought about it but it's just too much hassle.
MadBoy