Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 7th, 2003, 12:04 PM
Registered User
Join Date: Jun 2003
Location: Middleton, WI, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kpowers@wppisys.org
Default Weird Combo Box Data Binding Problem

Hello everyone,

I'm getting a strange error when I try to bind a combo box to a Dataset.
Here's my code!

Private Sub Get_Data()
            Dim sqlcmd = New SqlCommand("Select * from Utility order by
Utility", sqlConn)

            daDataAdapter = New SqlDataAdapter
            daDataAdapter.SelectCommand = sqlcmd

            dsDataSet = New Dataset
            daDataAdapter.Fill(dsDataSet, "Utility")

            sqlcmd = New SqlCommand("Select * from Adjustments", sqlConn)
            daDataAdapter = New SqlDataAdapter
            daDataAdapter.SelectCommand = sqlcmd

            daDataAdapter.Fill(dsDataSet, "Adjustments")

            daRel = New DataRelation("UtilAdjust",


        Catch ex As Exception
            MessageBox.Show(ex.Source.ToString & " - " & ex.Message,
Application.ProductName, _
            MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

    Private Sub BindFields()
            Dim ctrl As Control
            For Each ctrl In Me.Controls
                If TypeOf ctrl Is TextBox Then
                    ctrl.Text = ""
                End If


            For Each ctrl In Me.GroupBox1.Controls
                If TypeOf ctrl Is TextBox Then
                    ctrl.Text = ""
                End If

            cbUtility.DataSource = dsDataSet.Tables("Utility")
            cbUtility.DisplayMember = "UTILITY"
            cbUtility.ValueMember = "CODE"

            tbAN.DataBindings.Add("Text", dsDataSet,
            lblAK.DataBindings.Add("Text", dsDataSet,

            BindDate(tbASD, "UTILITY.UtilAdjust.AdjStartDate")
            BindDate(tbAED, "UTILITY.UtilAdjust.AdjEndDate")

            BindCurr(tbAA, "UTILITY.UtilAdjust.adjustment")

            BindType(cbType, "UTILITY.UtilAdjust.type")

            bmUtil = Me.BindingContext(dsDataSet, "Utility")
            bmAdjust = Me.BindingContext(dsDataSet, "UTILITY.UtilAdjust")

            AddHandler Me.BindingContext(dsDataSet,
"Utility").PositionChanged, _
            AddressOf dtUtil_PositionChanged

        Catch ex As Exception
            MessageBox.Show(ex.Source.ToString & " - " & ex.Message,
Application.ProductName, _
            MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

First I get my data by calling Get_Data(), Next I bind my data be calling

I get the following error when I hit these statements. cbUtility = combo
box = System.Windows.Forms.ComboBox
cbUtility.DataSource = dsDataSet.Tables("Utility")
cbUtility.DisplayMember = "UTILITY"

"Microsoft.VisualBasic - Cast from type 'DataRowView' to type 'String' is
not valid"

Another odd thing is when the exception is raised my "Catch" doesn't pick
up! I get an error message on those lines and the program keeps going? Also everything works correctly, all controls are bound correctly,
that combo box.

Reply With Quote
  #2 (permalink)  
Old February 12th, 2005, 04:52 PM
Registered User
Join Date: Feb 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

This one had me really frustrated, but the answer is to set the DataSource of a list control last - (ie out of logical sequence!) it didn't make sense to me, but it works!

Good luck


Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding Column Name to a Combo Box. jitu ADO.NET 3 June 27th, 2013 07:35 AM
Combo Box Complex Binding Example? pigparent VB Databases Basics 2 June 11th, 2008 12:08 PM
Binding a combo box to update a list view Amethyst1984 General .NET 0 February 28th, 2006 03:04 PM
binding recordset with combo problem emachines Access VBA 1 February 28th, 2005 04:10 PM
Weird Combo Box Binding Error kpowers@wppisys.org Pro VB.NET 2002/2003 0 October 8th, 2003 08:38 AM

All times are GMT -4. The time now is 09:21 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.