Solved

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

Posted on 2004-04-26
5
391 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
  • 3
  • 2
5 Comments
 
LVL 14

Accepted Solution

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now