Solved

Populate DataGridView from 3 DataBound DataTables with relational links making dynamic matrix

Posted on 2009-04-07
8
757 Views
Last Modified: 2013-11-26
Hi Experts,

I am using Visual Studio 2005, C#, .Net v2.0, DataSet controls to create XSD which write down to XML files for a Windows Form project. The XSD and XML files are all generated though Visual Studio... no database backends used.

I shall attempt to remove my real-world project names and make more general for ease of understanding. I am also going to simplify the table sizes.

I have three datatables of interest for this question and shall describe my desired outcome first.
I wish to have a DataGridView in a windows form.
The rows shall be peoples names, the columns shall be weekdays.
I wish the user of the DataGridView to be able to apply ticks to the matrix saying person1 did something on monday, wednesday etc and person2 did something on monday, tuesday and sunday etc.
The persons name and quantity of people shall be within Table1.
The days and quantity of days shall be within Table2 (maybe days is a bad example but it's a list which can grow and shrink)
There shall be a Table3 which contains the 'ticks'.

Table1 Columns: NameID[autonumber], Name[string], TicksID[int][unique]
Table2 Columns: DaysID[autonumber], Day[string]
Table3 Columns: TicksID[int],DaysID[int]

I have reservations as to if this is the correct way to implement my task... I welcome alternatives.
I also have no idea how I dynamically populate the DataGridView and bind the data.

I cannot be the first to come up with this kind of matrix requirement so perhaps there is more than one way to skin a cat?

Code snippets would be most welcome and I'd love some help with this problem.
I hope I have explained my situation sufficiently; if not please request additional information.


Thank you for your time.
0
Comment
Question by:craigewens
  • 5
  • 3
8 Comments
 
LVL 2

Author Comment

by:craigewens
ID: 24098286
Since I received no replies yet I decided to soldier on and see where it takes me...

I have Table1 and Table2 tables created and populated so decided to create a new form.
Within this form I added a new DataGridView control to it but did not bind to any data sources.
As the form loads, I loop through each row within Table2 extracting in turn the 'Days' and create columns within the DataGridView with a column HeaderText of the 'Day' string.
I then loop though each row within Table1 extracting in turn the 'Names' and add a new row to the DataGridView. I then title the new row with the 'Name' string using HeaderCell.Value.
# | MON | TUES | WED
--------------------------
BOB | X | [] | []
JAY | [] | [] | X
IAN | [] | X | X

On the face of it this seems to work but I have no idea how I store the resulting matrix back into a DataSet defined DataTable which is bound to the original header supplying rows (Table1 and Table2)

I'd ideally like to have Table1, Table2 and a Table3 all definable within the Visual Studio 2005 IDE DataSet designer window and the DataGridView bound to a DataTable.

Please can someone offer the missing piece of the jigsaw?

Perhaps I underestimated this task and as such didn't place enough points up for grabs which is why I've received no help yet... I'm happy to increase if the solution to my issue turns out to be a large one :-)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24100229
I think that a better approach would be to use the DataGridView in the virtual mode, where you can control what data is shown, and how that data is shown.
0
 
LVL 2

Author Comment

by:craigewens
ID: 24105149
Thank you for responding...
I have done a little reading on VirtualMode and fail to see what the advantage is over me doing it manually as I am currently having to do.

I create the columns and rows manually by looping through Table1 and Table2 rows and turning their values into column headers and row headers. I store the primary keys for the rows&columns within the Tag property of the header cells.
When the use presses "save" I iterate through the dgv finding a 'tick', where I do, I store the col header.tag in Table3 col1[dayid] and row header.tag in Table3 col2[nameid].
To populate I reverse... I am using the relationships defined within the DataSet designer to ensure (aka throw errors) when I put an id back into Table3 which doesn't exists in Table1 or Table2.

So; that's what I'm doing atm; if you still think VirtualMode is the way to go, please expand if you can; i'd appreciate it.
Thank you for your time.
0
 
LVL 2

Author Comment

by:craigewens
ID: 24105602
From reading more into the VirtualMode functionality, it's designed to deal with vast amounts of data and only really loading/presenting data as/when it's required rather than fully populating a control with too much data for it to handle.
For my application, I'm not dealing with a great amount of data, I'm just trying to make a matrix from two tables and have a 3rd (matrix) table which has bound rows/columns to other tables.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 2

Author Comment

by:craigewens
ID: 24106635
Seems I'm not going to get the desired answer that I wished for and my own way now seems more then stable for the job.

Anyone know how do I close the questions and refund the points?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24106840
It's funny how people think that this is my full time job.  I don't sit by my computer 24 hours a day, you know.  *BIG GRIN*

If you are happy with your solution, and you feel that it provides the level of functionality that you need, then my work is done.  If you are looking for a "better" way, then we can continue to hash over ideas.

If you are talking about something like a cross-tab display, then most of the work will need to be done from the backend, since the DataGridView can only bind to a single source.  

The virtual mode is handy if you need to handle complex data requirements, but doesn't fit all situations.

0
 
LVL 2

Accepted Solution

by:
craigewens earned 0 total points
ID: 24107669
lol, 'people' realise none of the experts on here work for EE but in some situations people also cannot wait periods of time for an answer which might or might not satisfy their needs. Nor can they solely rely on answers as they also don't work for EE and have their own deadlines.
EE is a resource (noted a great one!) just like any other forum and whilst waiting for responses people also look elsewhere.

My current implementation now works to a satisfactory manner and I guess since I've not had any queries requesting additional clarification I presume there isn't an obvious alternative.
I'm happy to keep the question open if you believe there is a better alternative; but I also don't wish to waste your time.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24111485
If you are satisfied with your solution, then go with it...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now