Solved

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

Posted on 2009-04-07
8
772 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

627 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