Avatar of andre72
andre72
 asked on

Add row headers to a DataGridView

Hi,

I've a simple DataTable like this:
ID | Name | isActiv

I create a DataView with and sort it by isActiv, Name .
Now I attach it as a DataSource to a DataGridView:
ID | Name | isActiv
1 | Andre1 | true
2 | Andre2 | true
3 | Andre3 | true
4 | Andre4 | true
5 | Andre1 | false
6 | Andre2 | false

This works fine but I like to give the active and also the none activ a row header like this:
Active ones
1 | Andre1 | true
2 | Andre2 | true
3 | Andre3 | true
4 | Andre4 | true
Inactive ones
5 | Andre1 | false
6 | Andre2 | false

The goal would be to let the groups expand / collapse on click but this is not necassary.
I know the great controls like eg. OutlookGrid and TreeDataGrid but I think there's no need to change my code to include such powerful controls for only insert two rows ...

Thanks

Andre
.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
Nasir Razzaq

8/22/2022 - Mon
Nasir Razzaq

>but I think there's no need to change my code to include such powerful controls for only insert two rows ...

I think otherwise.

1) Either use one of those controls which supports grouping
or
2) Use a dataset, create two datatables and a way of linking them (such as adding a groupid field depending on whether active or not). Then add a data relation based on this column. Now set the grid's datasource to this dataset and you will get a master details gridview.
andre72

ASKER
CodeCruiser, do you have a small sample of you solution No. 2 (DataSet)?
This sounds fine for me ...
ASKER CERTIFIED SOLUTION
Nasir Razzaq

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
andre72

ASKER
Thanks for your support
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Nasir Razzaq

Glad to help :-)