Solved

Create a Disconnected Dataset bound to a Datagrid

Posted on 2004-10-12
4
312 Views
Last Modified: 2010-04-23
I am forced to gather information from methods of a COM object, and display it in a datagrid. Of course the big problem is - NO Database! Boy is it hard to find help on this one. I thought I would ask you gurus.

How to I manually create and populate a dataset table & bind it to a noneditable datagrid (if that matters)? I am amazed at how difficult this seems. I have found other solutions to populate the datagrid, but they all have little quirks. I was told that datagrids should really be bound to datsets. Any ideas?
0
Comment
Question by:JeepGeekin
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12287578
Hi, Try this:

 Dim ds As New DataSet

   Private Sub FilldsManually_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

      Dim dt As New DataTable
      Dim dr As DataRow

      'Create dataTable
      dt.Columns.Add("MyFirstColumn")
      dt.Columns.Add("MySecondColumn")

      'Create DataRow
      dr = dt.NewRow
      dr("MyFirstColumn") = "Hello"
      dr("MySecondColumn") = "Bye"
      dt.Rows.Add(dr)

      ds.Tables.Add(dt)

      DataGrid1.DataSource = ds

   End Sub

   Private Sub AddRow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
      Dim dr As DataRow


      'Create DataRow
      dr = ds.Tables(0).NewRow
      dr("MyFirstColumn") = "Hello"
      dr("MySecondColumn") = "Bye"
      ds.Tables(0).Rows.Add(dr)

   End Sub
0
 

Author Comment

by:JeepGeekin
ID: 12288172
Oh sure. Make it seem that simple!
Looks like it works, but I am getting something new in my datagrid I have not seen before.

It shows up with just a plus sign. When I click on it, it shows me "Table1". When I click on Table 1, the data fills out the datagrid. Any idea why it is doing this?
0
 
LVL 10

Accepted Solution

by:
Hans Langer earned 500 total points
ID: 12288248
sorry, I forget this line:

DataGrid1.DataSource = ds
DataGrid1.DataMember = ds.Tables(0).TableName.ToString
0
 

Author Comment

by:JeepGeekin
ID: 12288265
Excellent!
I actually came back out to tell you I figured it out (with my tail between my legs). Thanks for your help. This is exactly what I needed!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

861 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