Results 1 to 10 of 10

Thread: How do I show the datagrid? [Resolved]

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    How do I show the datagrid? [Resolved]

    I've bound my datagrid to a dataset:

    VB Code:
    1. DataGrid1.DataSource = ds
    2. '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.

  2. #2

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Looky here:

    Attached Images Attached Images  

  3. #3
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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:
    1. Dim dt As DataTable
    2. dt = ds.Tables(0)
    3. DataGrid1.DataSource = dt

    or you could do it this way

    VB Code:
    1. DataGrid1.DataSource = ds
    2. DataGrid1.DataMember = "Table"

  4. #4

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Easy question?

  5. #5
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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.

  6. #6

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    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.

  7. #7
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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...

  8. #8

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

  9. #9
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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.

  10. #10

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    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
  •  



Click Here to Expand Forum to Full Width