fill a datagrid that is displayed on a modal form,from dataset

Posted on 2004-04-26
Last Modified: 2010-04-24
good day i have a frmMain.vb and a
frmList.vb. The latter is a form with a datagrid called gdDetails.

now i have a button on frmMain with the follwing code:

 Dim frmListNow As New frmList 'instantiate  frmList

        frmListNow.Show() 'show it

        MyOLEDBConnection.Open() 'open my connection

        Dim cmdFillCustomers As New System.Data.OleDb.OleDbCommand("SELECT Customers.* FROM Customers",

MyOLEDBConnection)'fill my oledbcommand

        Dim rdFillCustomers As System.Data.OleDb.OleDbDataReader = cmdFillCustomers.ExecuteReader
'set the oledbdatareader


my plan is to press the button,
and display frmList
then fill formlist with all the data of the oledbcommand cmdFillCustomers.

1. how can i get the grid on frmList to be populated with the values of the Oledbdatareader: rdfillcustomers
should i make a dataadapter now, fill the dataset, then load the frmList
and how do i populate it from there?
maybe export the dataset to a xml file, then display the frmList , then gather the data from the xml file?
should i put all the code in frmList and just call FRMLIST from frmMain and then somehow call frmList.Fill from there?

2. how can i get frmlist to display modal?

thank you!

Question by:jxharding
  • 3
  • 2
LVL 14

Accepted Solution

ptakja earned 500 total points
ID: 10918437
Hello.  This can be accomplished very easily:

1) Fill your DataSet in your frmMain
2) Create a Public property in your frmList that will accept your DataSet
3) Instantiate your frmList object
4) Pass the DataSet to the List form
5) Show the form modally by calling the ShowDialog method

see the code fragments below.

In your frmList, create a new Public property & corresponding private variable to accept your dataset object like this:

Private m_dstMyDataSet As DataSet     'Private member variable

Public Property MyDataSet As DataSet
       Return m_dstMyDataSet
   End Get
   Set(Value As DataSet)
       m_dstMyDataSet = Value
       ' Here you could bind the dataset to the grid:
       objGrid.DataSource = Value
       objGrid.DataBind()    ' <<<  You may or may not need this line depending on the grid you are using
   End Set
End Property

Now in frmMAIN's button event handler:

    MyDataSet = MyDataAdapter.Fill("SELECT * FROM MyTable", MyConnection)
   Dim frm As New frmList()     'Instantiate a List Form object
   frm.MyDataSet = MyDataSet

LVL 14

Expert Comment

ID: 10918468
Argg...hit tab and enter and the form posted.   (Too used to code editors...)   These comments should be appended to my previous post.

Anyway, you use ShowDialog to get the form to appear modally.

On your List form, if you create a couple buttons, say OK and Cancel and set their DialogResult property to the same (OK and Cancel) then when the user clicks those buttons the form is automatically closed and the ShowDialog method returns the DialogResult you put in the button.  You can then use this to determine what the user wants to do:

If frm.ShowDialog = DialogResult.OK Then   ' The user clicked the OK button
    'Update the data from the grid
End If

Finally dispose of the list form:


Author Comment

ID: 10926745
hi ptakja, thanks the answer is awesome and i learned a lot,could you please just help me on 1 small section still
in my fmMain i only have the following code
Dim daCustomers as
dim dsCustomers as Dataset

dsCustomers = daCustomers.fill ("SELECT * FROM CUSTOMERS",myconnection)
now i get the message overload resolution failed because no accessible 'fill' can be called with these argument
Public function fill(dataset ........

obviously im trying here on my own, but hopefully you can help me

Author Comment

ID: 10926914
i sorted that one myself thanks!
only one question left now
the user now selects a row on the frmList and in this frmList row, i need to take the row , the user chose and put it on a control on my frmMain.
Customer Name
Customer Address
Customer Telephone Number
what control should i use and how difficult would it , or rather what method should i use  to pass the values from the chosen row into the control?
thank you!
LVL 14

Expert Comment

ID: 10928688
Probably the easiest way to do what you want is to create several public properties (ie, CustomerName, CustomerAddress, CustomerPhone) in your frmList.  When the user clicks a row, copy the data from the row object to the properties.  Then when they close the modal form, you can query the properties prior to destroying the form:

IF frmList.ShowDialog = DialogResult.OK Then
    txtName.Text = frmList.CustomerName
    txtAddress.Text = frmList.CustomerAddress
    txtPhone.Text = frmList.CustomerPhone
End If


Thank help?

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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