Wrox Programmer Forums
|
BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5
This is the forum to discuss the Wrox book Beginning Visual Basic 2005 Databases by Thearon Willis; ISBN: 9780764588945
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 11th, 2006, 04:00 PM
Authorized User
 
Join Date: Aug 2005
Posts: 88
Thanks: 4
Thanked 0 Times in 0 Posts
Default CurrencyManager

I am using the examples in "Beginning Visual Basic 2005 Databases" as a model for a program I'm writing to maintain employee record. I use the Access 2000 database.

I'm trying to loop through the table to fill a ComboBox but the example using the Data Class doesn't include the CurrencyManager which I need to loop through the table with a "Do Until" procedure.

In VB6 I would have coded it as:
   Do Until Recordset.EOF
      CBO.Add Recordset!Field
   End Do

I have tried to create a CurrencyManager without success. Is there any other way to accomplish this using the Data Class recommended?

Alternatively, what code can I insert in the Data Class to recognize the CurrencyManager?

Thank you.


 
Old April 11th, 2006, 07:48 PM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

If I understand you correctly, all you want to do is to load a combo box on the form with data from a DataTable. The simpliest way is to use code such as this:

                ComboBox1.DataSource = objDataTable
                ComboBox1.DisplayMember = "Ingredient"
                ComboBox1.ValueMember = "IngredientID"

This assumes that objDataTable is declared as a DataTable and the DataTable is populated and contains two fields; Ingredient and IngredientID. The first field is what gets displayed to the end user in the drop down portion of the combo box and the second field is used to look up or tie the selected entry in the combo box to another variable or object. In my case, IngredientID is the primary key of the ingredients in the database.

I hope this helps.

Thearon
 
Old April 13th, 2006, 07:27 AM
Authorized User
 
Join Date: Aug 2005
Posts: 88
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Thearon

Thank you for the quick response. When I try to use it, however, when I enter the code I get messages telling me that DisplayMember and ValueMember are not
a "..member of System.Windows.Forms.ToolStripComboBox."

My code looks like this:

Using objData As New WDABase
tscboSearch.DataSource = objDataTable
tscboSearch.ValueMember = "EmployeeID"
tscboSearch.DisplayMember = "DisplayName"

 
Old April 14th, 2006, 12:38 PM
Authorized User
 
Join Date: Aug 2005
Posts: 88
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Since my last post on this subject I have been trying different ideas for solving the problem. I finally settled on using the ListView as is used in the Time Tracker application.

I was able to get the ListView to display the one field that I want displayed. Rather then the one columns I want listed, The ListView shows as three columns and the content of the one field breaks up to fit one of the three columns. The correct field is displayed, only the display is wrong.

My code is as follows:
Private Sub FillList()

'Declare variables...
Dim objListViewItem As ListViewItem

'Initialize a new instance of the Data Access base class.(WDABase)...
Using objData As New WDABase
    Try
       'Get all employee records...
       objData.SQL = "usp_SelectList"
       objData.InitializeCommand()
       objData.OpenConnection()
       objData.DataReader = objData.Command.ExecuteReader
       objData.DataReader.Read()

       'See if any data exists before continuing...
       If objData.DataReader.HasRows Then
          'Clear previous list...
          lvStaff.Items.Clear()

          'Process all rows...
          While objData.DataReader.Read
            'Create a new ListView item...
            objListViewItem = New ListViewItem

            'Add the data to the ListView item...
            objListViewItem.Text = objData.DataReader.Item("DisplayName")

            'Add the ListViewItem to the ListView control..
            lvStaff.Items.Add(objListViewItem)
                    End While
       End If
       objData.DataReader.Close()
   catch ex As Exception
          MessageBox.Show(ex.Message)
   End Try
  End Using
End Sub

I can forward a screen print of the end result if this will help.

Thanks again for trying to help, I hope that i explained my problem understandably.

 
Old May 1st, 2006, 05:20 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

I screen shot would be helpful in trying to assess what you are explaining.

Thearon
 
Old May 7th, 2006, 09:55 AM
Authorized User
 
Join Date: Dec 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to luishrd
Default

I wonder if you solved this already, before I go crazy trying to do it on my end.... if you read this, please let me know either way so I can either start trying the ComboBox on ToolStrip thing or learn how you did it.

Thanks.
 
Old May 14th, 2006, 02:06 PM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

I have not solved this as I'm still trying to assess what exactly it is you want to accomplish. You mention populating a combo box, then you mention a listview. These are two very different controls. Could you be more specific in your business requirements so I can properly assess the correct control that you should be using.

Thearon
 
Old July 20th, 2006, 01:27 PM
Authorized User
 
Join Date: Aug 2005
Posts: 88
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Thearon

I didn't respond with the examples that you requested as I have been off of work (surgery) for several months and I am back now and still tryin, unsuccessfully to fil s combo box. Heres the last code I tried.

Using objdata As New WDABase
            objdata.SQL = "usp_SelectAll"
            objdata.InitializeCommand()
            objdata.OpenConnection()
            objdata.DataReader = objdata.Command.ExecuteReader
            cboSearch.DataSource = objdata.DataReader
            cboSearch.DisplayMember = "DisplayName"
            cboSearch.ValueMember = "StaffIndex"
        End Using

This results in an error message "Argument exception was unhandled
Complex DataBinding accepts as a data source either an IList or an IListSource."

I could find no reference t IList in the CBO properties and completely lost.

 
Old July 24th, 2006, 05:13 PM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

You cannot use a DataReader to populate a combo box. The combo box must be bound to either a DataSet, DataTable, or DataView. Remember that a DataReader holds a connection open to the database and only reads one record at a time.

Thearon
 
Old July 25th, 2006, 07:08 AM
Authorized User
 
Join Date: Aug 2005
Posts: 88
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Thearon

Thank you for the response, that explains why it didn't work.






Similar Threads
Thread Thread Starter Forum Replies Last Post
CurrencyManager and BindingContext cbm007 C# 1 August 20th, 2005 03:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.