DataTable columns inside columns or merged row table structure - c#

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.

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

Related

UWP - Matrix With Grid

I first would like to say that I am fairly new to UWP, and my experience with Android is probably leading some some assumptions on my end. There may be a better way about this, but so far I have been trying to use the Grid class, but it doesn't seem to work in a way that I would expect.
Basic Idea
I am trying to create a UWP application with the ability of organizing elements in a matrix, where each row and column represents some category, and whatever element that is within both row and column categories is placed in that cell. One or more elements can be listed in each matrix coordinate. An image for reference is below:
To give a more clearer/specific example, let's say the Elements were Employees, rows were Teams, and columns were disciplines (Testing, Dev, Management)
Comparing different category-types can be useful for displaying information, but this will have greater importance beyond just names, so this is only a simplified example. Also, as shown in the example, the number of rows and columns is determined by the number of categories there are for each respectively (e.g. # rows = # teams and # columns = # disciplines).
I don't have any code to show, simply because this isn't so much an error problem as it is a conceptual problem.
My Questions
How would I be able to filter what elements are bound to a cell by their Row/Column? Is this even possible?
i.e. populating the cells of the matrix with elements that occupy both the corresponding row's and column's category.
How do I bind columns and rows to their respective list of categories?
e.g. whenever I add another Column Category, a new empty column will be generated.
I appreciate your help and time!
For your scenario, the better way is using DataGrid to replace.
i.e. populating the cells of the matrix with elements that occupy both the corresponding row's and column's category.
You could use binding way to specific current element in which column and row, but you need to calculate before preparing data source for Grid panel.
whenever I add another Column Category, a new empty column will be generated.
If you use DataGrid, it will generate Column base on your item's new filed. Here is code sample that your could refer.

Rdlc with two "synchronized tables"

I'm using rdlc files to generate pdf files.
What I basically want to do to is to display the data of my data set on two "synchronized" tables.
The image below represents the result I would like to obtain:
The image represents one page of the pdf, on which the data is group by a certain attribute of the dataset.
Please tell me if any clarification is needed, it's hard for me to explain clearly.
How can i do that with 2 tables as a single object?
I managed to do this with a Tablix as the container. Add two lines of header and add another two Tablix to each cell of header with data. You cannot use Data row, you have to remove it. You can add a Tablix to a cell with drag and drop.
In the end, you will have something like :
Probably something alike can be achieved with subreports, but I'm not familiar with them.
EDIT:
Added screenshot
I believe this is what you want to see. 1 column, 3 rows Tablix. In Cells(1,1) and (3,1) you have other Tablix objects that you can customize.

How can I create a WPF data grid with an enhanced table header?

I'm currently working on a WPF based data management system, which is planned to replace the old Excel based one. This old system is mainly consist of tables where the user can input his data. One of these tables looks like this:
The number of rows and columns are fixed (25 rows per day, from 6AM to 6AM the next day).
It is kinda difficult to provide an input form for this kind of data, so I tried implementing the table in WPF using a DataGrid. However, I wasn't able to get these nifty merged cells, especially in the first and second row.
Are there any 'DataGrid' usercontrols on the market that allow merging cells, shading rows etc.? Or is there any other way of providing an user-friendly input form that I've overlooked?
If you're looking for Grid cell merging tool you can try Devexpress.
Here is a link on how to merge DataGrid cells using Devexpress
Another solution to merge DataGrid Rows is to use a ListBox

How to use multiple List<> as DatagridView's datasource

I'm looking for a highly efficient way to save data to a table like structure in C#. The number of rows, columns and data type for each column is determined at runtime. One of my approaches is to create a struct that defines a column. The struct consists of ColumnName, Units, and a generic List of doubles. (For now I am sticking to one data type). I then instantiate a struct for each column and fill its list. This method works pretty well and is much cleaner than some other methods we've tried, I am able to save 100,000 rows of 3 columns in about 12 milliseconds.
The problem I am having is displaying the data. I am able to display my "table" in a datagridview by looping through my columns and rows and filling the DGV cell by cell, but this is, not suprisingly, very slow.
Is there a way to use my 3 lists as a datasource for the DGV? Can each column have it's own datasource? Is the an alternative to the DataGridView that I should try?
What are the "3 lists" here? I can see the list of doubles... if the columes are dynamic, then implementing ITypedList might be useful, but I'll be honest - it is a pig to implement correctly; it would be easier to fill a DataTable. I've used this, for example, to transpose an array on the fly.
If performance is your concern, perhaps switch to virtual mode? This would appear to match your use-case quite well.
Have you tried filling a DataTable first and then binding that DataTable to the DataGridView?
If it's a WebApplication you can do a foreach statement and build a table from code-behind.

Cleanest way to implement collapsable entries in a table generated via asp:Repeater?

Before anyone suggests scrapping the table tags altogether, I'm just modifying this part of a very large system, so it really wouldn't be wise for me to revise the table structure (the app is filled with similar tables).
This is a webapp in C# .NET - data comes in from a webservice and is displayed onscreen in a table. The table's rows are generated with asp:Repeaters, so that the rows alternate colers nicely. The table previously held one item of data per row. Now, essentially, the table has sub-headers... The first row is the date, the second row shows a line of data, and all the next rows are data rows until data of a new date comes in, in which case there will be another sub-header row.
At first I thought I could cheat a little and do this pretty easily to keep the current repeater structure- I just need to feed some cells the empty string so that no data appears in them. Now, however, we're considering one of those +/- collapsers next to each date, so that they can collapse all the data. My mind immediately went to hiding rows when a button is pressed... but I don't know how to hide rows from the code behind unless the row has a unique id, and I'm not sure if you can do that with repeaters.
I hope I've expressed the problem well. I'm sure I'll find a way TBH but I just saw this site on slashdot and thought I'd give it a whirl :)
When you build the row in the databinding event, you can add in a unique identifier using say the id of the data field or something else that you use to make it unique.
Then you could use a client side method to expand collapse if you want to fill it with data in the beginning, toggling the style.display setting in Javascript for the table row element.
just wrap the contents of the item template in an asp:Panel, then you have you have a unique id. Then throw in some jquery for some spice ;)
edit: just noticed that you are using a table. put the id on the row. then toggle it.

Categories

Resources