Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-04-26
5
Medium Priority
?
400 Views
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



        MyOLEDBConnection.Close()


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!

 
0
Comment
Question by:jxharding
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
ptakja earned 2000 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
   Get
       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
   frm.ShowDialog()


0
 
LVL 14

Expert Comment

by:ptakja
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
    MyDataAdapter.Update(frm.MyDataSet.GetChanges())
End If

Finally dispose of the list form:

frm.Dispose()
0
 

Author Comment

by:jxharding
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 system.data.oledb.oledbdataadapter
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
thanks!
0
 

Author Comment

by:jxharding
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.
e.g.
-------------------------------------------
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!
0
 
LVL 14

Expert Comment

by:ptakja
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

frmList.Dispose

Thank help?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

610 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