Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview?
Set datasources for each column in datagridview? Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Go Back  Xtreme Visual Basic Talk > > > Set datasources for each column in datagridview?


Reply
 
Thread Tools Display Modes
  #1  
Old 04-09-2006, 08:58 PM
wolfmanyoda's Avatar
wolfmanyoda wolfmanyoda is offline
Regular
 
Join Date: Jan 2003
Location: Indiana
Posts: 90
Default Set datasources for each column in datagridview?


I have filled a dataset with data from multiple tables and I would like to show parts of that data in one datagridview control.
Is it possible to set a different datasource for each column?
Thanks.
Reply With Quote
  #2  
Old 04-09-2006, 10:28 PM
silenuz silenuz is offline
Junior Contributor
 
Join Date: Aug 2005
Location: Ottawa
Posts: 203
Default

To the best of my knowledge this is not possible . It may be possible with datagrid control but I don't think so. You'll probably have to work on you SQL for this, and query the necessary information using a join or union, depending on what kind of result you want. http://www.cryer.co.uk/brian/sql/sql_crib_sheet.htm
Reply With Quote
  #3  
Old 04-10-2006, 10:07 AM
MKoslof's Avatar
MKoslofSet datasources for each column in datagridview? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

If you are using VS 2005 then its actually quite easy. Each column can be assigned a seperate Objectdatasource. The Object data source models were introduced in VS 2005. If you are using the standard Dataset or DataTable route to populate a bound datagrid, you can't do this.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #4  
Old 04-10-2006, 10:29 AM
wolfmanyoda's Avatar
wolfmanyoda wolfmanyoda is offline
Regular
 
Join Date: Jan 2003
Location: Indiana
Posts: 90
Default

Quote:
Originally Posted by MKoslof
If you are using VS 2005 then its actually quite easy. Each column can be assigned a seperate Objectdatasource. The Object data source models were introduced in VS 2005. If you are using the standard Dataset or DataTable route to populate a bound datagrid, you can't do this.
Yes, I am using 2005.
I'll look into the ObjectDataSource, sounds like it may do the trick.
Thanks.
Reply With Quote
  #5  
Old 04-10-2006, 10:48 AM
MKoslof's Avatar
MKoslofSet datasources for each column in datagridview? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

No problem . The new GridView in VS 2005 is very flexible..I had a tutorial on this, I just don't remember the URL location . Good luck, let me know if you have any more questions.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #6  
Old 04-10-2006, 10:58 AM
wolfmanyoda's Avatar
wolfmanyoda wolfmanyoda is offline
Regular
 
Join Date: Jan 2003
Location: Indiana
Posts: 90
Default

Is the ObjectDataSource only for ASP apps?
I'm only finding information on it as it relates to ASP and I'm working on a windows form.
Reply With Quote
  #7  
Old 04-10-2006, 11:29 AM
silenuz silenuz is offline
Junior Contributor
 
Join Date: Aug 2005
Location: Ottawa
Posts: 203
Default

You might find some information in the datagridview samples package from the following:
http://www.windowsforms.net/Samples/...220&tabindex=4
Reply With Quote
  #8  
Old 04-10-2006, 11:40 AM
MKoslof's Avatar
MKoslofSet datasources for each column in datagridview? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Nope, it works for WinForms and WebForms, no ASP vs WinForm distinction
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #9  
Old 04-10-2006, 12:40 PM
IUnknown's Avatar
IUnknown IUnknown is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Oct 2004
Location: Montréal
Posts: 1,135
Default

I'm just starting to look at the ObjectDataSource. Er MKoslof, are you sure that it can be used on both WinForms & WebForms? MSDN2 said this:

The ObjectDataSource is an ASP.NET data source control that represents a data-aware middle-tier object or a data-interface object to data-bound controls.
__________________
win7 : vs 2008 : .Net 3.5
Reply With Quote
  #10  
Old 04-10-2006, 06:24 PM
wolfmanyoda's Avatar
wolfmanyoda wolfmanyoda is offline
Regular
 
Join Date: Jan 2003
Location: Indiana
Posts: 90
Default

Not having much luck doing it this way, so I'm going to try out the SQL idea from silenuz.
My SQL skills are pretty poor so it will be good exercise.
Reply With Quote
  #11  
Old 04-10-2006, 07:03 PM
silenuz silenuz is offline
Junior Contributor
 
Join Date: Aug 2005
Location: Ottawa
Posts: 203
Default

You can also use the JoinView class described in the following article http://support.microsoft.com/default...b;en-us;325682. Using this class you can join two or more DataTables together. This JoinView can then be databound to the DataGridView. Just a straight SQL statement might be easier however.
Reply With Quote
  #12  
Old 04-11-2006, 12:16 PM
MKoslof's Avatar
MKoslofSet datasources for each column in datagridview? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

OK, sorry a miscommunication on my part. Yes the SQL and Object Data Sources are used in ASP.net. In a WinForms application you want to look at the properties of the BindingSource object. I've doing a lot of ASP.net development recently and I forgot that Winform and WebForm GridView binding is slightly different

http://msdn.microsoft.com/vcsharp/pr...ms02172004.asp
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #13  
Old 04-11-2006, 12:46 PM
IUnknown's Avatar
IUnknown IUnknown is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Oct 2004
Location: Montréal
Posts: 1,135
Default

Thanks MKoslof, I was getting a little worried that I didn't see any ObjectDataSource documentation on the WinForm version of the DGV.
__________________
win7 : vs 2008 : .Net 3.5
Reply With Quote
  #14  
Old 04-11-2006, 01:03 PM
MKoslof's Avatar
MKoslofSet datasources for each column in datagridview? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

I have done exactly what the poster wants to do in ASP.net and I had a brain lapse for a second. In ASP.net you would just create template columns and define a seperate ObjectDataSource to the columns, if a "value list" type interface column (a drop down list in one column with values from a seperate data store that tie back to a key, etc.) is needed. The new ObjectDataSource objects take parameters and sorting params.

In WinForms I know you can do something comparable but you need to define your own column objects. I *believe* each column object can take its own bindingsource, but I don't recall exactly how to do this given that type of scenerio. But I know similar functionality can be gathered.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #15  
Old 04-11-2006, 07:41 PM
wolfmanyoda's Avatar
wolfmanyoda wolfmanyoda is offline
Regular
 
Join Date: Jan 2003
Location: Indiana
Posts: 90
Default

Thanks for all of the help, still not working but I haven't given up.
I just stumbled across this article.
I'm going to dive into this example and see if I can make mine work this way.
If I ever get it going I'll let you know how I did it.
Reply With Quote
  #16  
Old 04-12-2006, 12:22 PM
MKoslof's Avatar
MKoslofSet datasources for each column in datagridview? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

What is the final goal here? Do you want to have custom columns, such as a combo box that contains a drop down list of information for another data source, or tie a key value to a collection of data that resides in a single column, etc.

If you simply want to display data from several tables in one GridView the easiest way is to just use one DataSource but make its query definition from a SQL JOIN or data pull of several tables.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #17  
Old 04-13-2006, 08:06 AM
wolfmanyoda's Avatar
wolfmanyoda wolfmanyoda is offline
Regular
 
Join Date: Jan 2003
Location: Indiana
Posts: 90
Default

What I'm aiming for is to have a grid with 4 columns: 2 read-only, 1 that will have data programmatically added to it and saved back to the database, and the fourth column will be unbound, only displaying computed data that will not be saved anywhere.

The data will come from 3 tables. Tables 1 and 3 have a many-to-many relationship with table 2 associating them.

The columns on the form would look like this:

Column 1: Table1.Field1 (where Table1.Field1 = Table2.Field1)
Column 2: Table1.Field2
Column 3: Table3.Field1 (this one may be changed by program and saved back to db)
Column 4: Computed field

I hope that made sense.
Reply With Quote
  #18  
Old 04-13-2006, 10:10 AM
MKoslof's Avatar
MKoslofSet datasources for each column in datagridview? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

OK, well this is what you can do. You can bind your grid to a single datasource, this is where you might have issues. Since in WinForms I *think* you can still only have one databound source per grid. Then you would add two UNBOUND columns to your grid. These columns can be specific control types such as checkboxes, a combo box, etc.

After binding the Grid, you have x number of columns populated (with the bound data). Then you can manually build the other two columns. I've haven't done much with this in the WinForms world, but you should be able to populate the unbound columns programmatically. Let me see if I can come up with an example
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #19  
Old 04-13-2006, 10:33 AM
wolfmanyoda's Avatar
wolfmanyoda wolfmanyoda is offline
Regular
 
Join Date: Jan 2003
Location: Indiana
Posts: 90
Default

That was my original idea, I filled a dataset with the 3 tables but couldn't figure out how to set each column to the appropriate fields.
Reply With Quote
  #20  
Old 04-13-2006, 10:39 AM
MKoslof's Avatar
MKoslofSet datasources for each column in datagridview? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Quote:
That was my original idea, I filled a dataset with the 3 tables but couldn't figure out how to set each column to the appropriate fields.
What do you mean here? So you need to take the BOUND data in the bound columns and populate your UNBOUND columns with data from these bound columns?
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview? Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
 
Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
 
-->