Solved

2 DataGrids(parent/child) of a Relationel tables

Posted on 2004-10-08
12
383 Views
Last Modified: 2010-04-15
Hi,

I have 2 talbes in a DataSet, and made a DataRelation between the 2 tables in the DataSet.

One of the Tables are displayed in a datagrid, and when one of them is selected in the datagrid I want its childrows to be displayed in a second datagrid.

How can I get only the related data into the second datagrid, or maybe use a filter, to only get the child rows??

I totally blank on this one.

I use ByteFX to connect to a mysql database, but the same problem is there if MSSQL :-(

Here are my code:
private void Form1_Load(object sender, System.EventArgs e)
{
    MySqlConnection thisConnection = new MySqlConnection("Server=syska.dk; Username=root; Password=supermand; Database=c-sharp;");
   
    MySqlDataAdapter thisPollAdapter = new MySqlDataAdapter("SELECT * FROM poll", thisConnection);

    MySqlDataAdapter thisOptionAdapter = new MySqlDataAdapter("SELECT * FROM pollOption", thisConnection);

    thisPollAdapter.Fill(thisDataSet, "first");

    thisOptionAdapter.Fill(thisDataSet, "second");
   
    dataGrid.DataSource = thisDataSet.Tables["first"];

    DataRelation thisRelation = new DataRelation("thisRelation", thisDataSet.Tables[0].Columns["pollId"], thisDataSet.Tables[1].Columns["pollId"]);

    // MessageBox.Show( thisDataSet.Tables[1].ParentRelations. );

    // her skal de columns smides ind som passer til det ID som er valgt i det anden datagrid
    // dataGrid1.DataSource =
}

As you can see, I havent made anything fancy yet. Are this the right way to go, or are there are better way of doing this, I dont want to get all the data every time, I choose a new row in the first datagrid..

kind regards
Mikael Syska
0
Comment
Question by:syska
  • 6
  • 4
12 Comments
 
LVL 8

Expert Comment

by:gregasm
ID: 12260178
0
 
LVL 8

Expert Comment

by:gregasm
ID: 12260187
Do you have Yukon? It is still in Beta and probably should not be released into Production yet! haha..

But what are you trying to do?

1. Keep the data TOTALLY UP TO DATE AT ALL TIMES AT ALL COSTS.

2. Keep the data clean by IMPLEMENTING PESSIMISTIC or OPTIMISTIC CONCURRENCY.

"please advise.."
0
 
LVL 8

Expert Comment

by:gregasm
ID: 12260319
oops! sorry, that last posting I made at 9:07AM.. that was for a different question! hahaa DOH!
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:syska
ID: 12260636
gahhh, really that simple :-)

I had the question asked on microsoft news group and a other danish forum, no answer there for 2 days, and then u answer it in like NO TIME

Amazing :-P

A few more things:

how do I remove that + sign, to the left, where the relation name becomes visable, when I click at it?

How do I set the Column width? I can find to set the default width but not for each column?

think that will be all for now
0
 
LVL 8

Accepted Solution

by:
gregasm earned 125 total points
ID: 12260887
Would you mind opening another question for the follow up questions you asked above? Thanks. =]]
0
 

Author Comment

by:syska
ID: 12260991
Will consider it, since I aint got so many points
0
 
LVL 8

Expert Comment

by:gregasm
ID: 12261553
How come you gave the answer a C grade?
0
 

Author Comment

by:syska
ID: 12263429
hmm, sorry :-/

Took the wrong one, It should have been A, but I must have taken the wrong one.

The solution was the first comment.

But just a little irritated that he would not answer the 2 other questions, that I had to his solution, but it he wont, I can't make him :-(

Will just have to wait until I get some more points :-P

thanks
0
 
LVL 8

Expert Comment

by:gregasm
ID: 12263611
I'll be happy to answer your other questions, but please try to look at this from our point of view. The individual questions (with the clear start and the clear end) are our incentive to reply and offer help. Without the incentive, then you'd have a newgroup, or a forum, and the questions would not be answered for a few days.

The points are an incentive for us to answer the questions quickly and completely as well. Otherwise, this would be no different than a newgroup or a forum, where the questions may not be answered for a while.

Thanks for your consideration =]]
0
 

Author Comment

by:syska
ID: 12263923
yahh, but still its very related questions to my question, its not like its about something completely different :-P
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

778 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