|
-
Jun 25th, 2004, 05:15 AM
#1
How do I show the datagrid? [Resolved]
I've bound my datagrid to a dataset:
VB Code:
DataGrid1.DataSource = ds
'I dont need to tell you what ds is :)
But when I run the application, the grid shows up all collapsed. I have to expand it, then click "table1" and then it shows the contents.
Is there any code I can use to have the grid displaying everything, so that I don't need to click click click?
Last edited by mendhak; Jun 25th, 2004 at 05:42 AM.
-
Jun 25th, 2004, 05:16 AM
#2
-
Jun 25th, 2004, 05:37 AM
#3
Hyperactive Member
Actually this is one of the easier questions that get asked here pretty often, I wish I could find one of the other threads I answered this on. The answer is this:
VB Code:
Dim dt As DataTable
dt = ds.Tables(0)
DataGrid1.DataSource = dt
or you could do it this way
VB Code:
DataGrid1.DataSource = ds
DataGrid1.DataMember = "Table"
-
Jun 25th, 2004, 05:42 AM
#4
Easy question?
-
Jun 25th, 2004, 06:02 AM
#5
Hyperactive Member
Perhaps it's because I have done so much work with ADO.NET that this is easy for me, but it basically comes down to this:
A dataset is a container for one or more datatables, if you attach your dataset to a datagrid then unless you tell it which table to use it has no other option than to display them all in a list so that you can select the one that you want to view. Setting the datamember property tells the table which table in your dataset is the one to use for display.
-
Jun 25th, 2004, 06:26 AM
#6
Originally posted by CyberHawke
Perhaps it's because I have done so much work with ADO.NET that this is easy for me, but it basically comes down to this:
A dataset is a container for one or more datatables, if you attach your dataset to a datagrid then unless you tell it which table to use it has no other option than to display them all in a list so that you can select the one that you want to view. Setting the datamember property tells the table which table in your dataset is the one to use for display.
I was aware of the concept of datasets and ADO.NET, but this is the first time I've used a datagrid. I was just testing out some Data Access Application Blocks.
Do you have any idea of those? If so, please look at my other thread.
http://www.vbforums.com/showthread.p...hreadid=294922
If not, go have yourself a nice cold beer.
-
Jun 25th, 2004, 06:49 AM
#7
Hyperactive Member
I had read this post previously and had navigated to the page that you had the link for. I haven't had time to dive in and determine if my methodology is in line with this pattern but I'm doing that as soon as I type this post and click the submit button...
-
Jun 25th, 2004, 06:54 AM
#8
-
Jun 25th, 2004, 07:26 AM
#9
Hyperactive Member
Although I have code modules that are similar in nature to this, they are nowhere near as complex as what Microsoft has written. It's taking what I have written in my projects and streched it out to the n'th degree.
Good stuff, and it's received great ratings from the developer community. I'm probably going to compile and use it in my future projects where data access involvs Sql Server.
-
Jun 25th, 2004, 07:35 AM
#10
Thanks a lot for your time. Mucho appreciatedo.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|