Widunder
Widunder

Reputation: 295

DataTable columns inside columns or merged row table structure

I've had a Google but I find no answer. You know how say in MS Word, when you insert a table, you can merge the columns of one single row to create a column-less row? Or have say a main header and then more columns inside it? Like so:

Merged Row:

|Column 1|Column 2|Column 3|

|Value|Value|Value|

|Merged Row|

|Value|Value|Value|

God the text formatting is awful on this web-site...and the Header Column example:

|Main Header||Another Main Header|

|Column 1|Column2||Column1|Column2|

I'm trying to achieve this in a written DataTable in C# which is being populated by an array. But I'm interested in changing its structure as one of the above, whichever is possible/easier.

So I've created my DataTable and added normal columns and rows etc. But I'd like to create either a merged row or a main header to display. Instead of having a repeated value in a single column for the values I am getting.

Can someone please provide a quick example on how I could achieve either one of those? Because repeated value will just look ugly.

Cheers.

Upvotes: 0

Views: 1213

Answers (1)

Widunder
Widunder

Reputation: 295

You're talking about displaying data in a particular way but a DataTable has nothing to do with display. It is for storage and that's that. How you display the data is up to you. The same data can be displayed in innumerable different ways. In a WinForms app, one of the most common ways to display the contents of a DataTable is with a DataGridView. You can choose which columns to display and merge cells in that grid if desired. In short, you're looking in the wrong place to do what you want to do. It is a presentation issue, not a data issue. –

jmcilhinney

Upvotes: 0

Related Questions