473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How do I display data from 2 tables in a datagrid?

Hi

My data is held in XML. I have 2 tables one with some time entry data
and the other with some project related data - here is the much
simplified version:

TimeEntries (table)
- StartTime (column)
- ProjectID (column)

Projects (table)
- ProjectID (column)
- ProjectName (column)

The two tables are related on ProjectID.

What I am trying to do is display my time entries with the ProjectName
in a datagrid (winforms) - spreadsheet style - like this:

StartTime | ProjectName
-------------------------
09:00 | MyProject

What is the best way to achieve this? I know I could create a new
dataset with a new datatable and brute-force the data in but that is
so ugly. I have tried creating a dataview and adding a new column but
when I saved the data back the new column was also there!

Surely there must be an elegant way to do this?!? Can anyone put me
out of my misery?

Regards, Jon
Nov 17 '05 #1
4 2050
Jon,

Just create a datarelation
In this message from yesterday it is set

http://groups-beta.google.com/group/...29d47a02137ebd

I hope this helps,

Cor
Nov 17 '05 #2
Thanks for the reply. I now believe that I need to use a
DataViewManager... something like this:

mySchema.ReadXml("MyFileName.xsd");
mySchema.Relations.Add("TimeProjects",
mySchema.Tables["Projects"].Columns["ProjectID"],
mySchema.Tables["TimeEntries"].Columns["ProjectID"]);
DataViewManager dvManager = new DataViewManager(mySchema);

But I still cannot figure out how to get the column into the datagrid -
doing the following would not include the ProjectName column:

this.dataGrid1.SetDataBinding(dvManager, "TimeEntries");

Can anyone offer any more advice?

Regards, Jon

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3
Jon,

The most simple way is first doing after setting the relations to the
dataset.

datagrid1.DataSource = YourDataset;

After that you can start playing with the dataviewmanager
Nov 17 '05 #4
I am only starting to mess with the dataviews and dataviewmanagers
myself, but maybe this will help. There is a method of the
dataviewmanager that you can call the will return an instance of a
dataview based on the dataviewmanager. I think you have to bind the
dataview that is created from this method rather than trying to bind it
to the dataviewmanager object itself.

DataView myDV = dvManager.CreateDataView(???);
this.dataGrid1.DataSource = myDV;
From the samples I have played with so far, the ??? is a dataset. From

your code listed I don't what should go here.Anyway,maybe this will
help you move in the right direction.

- Andrew

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chumley the Walrus | last post by:
IN my code behind .vb page for a delete records script (this also does a deletion confirmation with a javascript popup, this gets called on my front .aspx page with the datagrid), I'm not sure if...
18
by: Alpha | last post by:
Hi, I'm working on a Windows applicaton with VS 2003 on windows 2000. I have a listbox that I have binded to a dataset table, "source" which has 3 columns. I would like to display 2 of those...
2
by: Josef Meile | last post by:
Hi, I'm using a ComboBox, some Textboxes, and a DataGrid to represent a many-to-many relationship between Person and Course. Each time that I change the value in the ComboBox (which for now is...
1
by: Craig Banks | last post by:
If a row of data in a dataset has a lot of columns the row displaying the data in a datagrid will run way off the screen. What I'd like to do is display a row of data over several datagrid rows so...
4
by: Joe Van Meer | last post by:
Hi, Is the datalist meant for one table or can I use it to display information from 2 different tables? Or should I be looking at a datagrid instead? I began my code and kinda ran into a snag...
2
by: news | last post by:
hi im new in the .net environnement i have a work to do in school im able to display a datagrid using a database in access and im also able to display a datagrid using a database in foxpro 8.0...
3
by: JJ | last post by:
I have a datagrid on my form that displays its data from various tables within a specified dataset. That all works correclty. However, when one cell is selected prior to changed the displayed...
2
by: Cindy | last post by:
Hello. For some reason, I am able to "connect" to the Northwind database whenever I use the wizard; however, when I run the application, my datagrid does not display. Here are the exact steps I...
1
by: geeteshss | last post by:
First i would like to thank those persons who helped me out in solving my earlier problems the present problem is that i am unable to display data in datagrid....... but the data is visible in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.