CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Combo Boxes

  1. #1
    Join Date
    Feb 2009
    Posts
    192

    Combo Boxes

    Hi,

    The following code gives an error - at run time

    InvalidCastException was unhandled
    Operator '=' is not defined for type 'DatarowView' and 'Nothing'

    Code:
    If Not Me.CmbTruckTyp.SelectedItem = Nothing Then
    
     Select Case Me.CmbTruckTyp.SelectedItem.ToString
        Case "Mercedes-Benz"
             cmdMercBenzModels.Visible = True
             cmbDafModels.Visible = False
        Case "Daf"
             cmdMercBenzModels.Visible = False
             cmbDafModels.Visible = True
        Case Else
             cmdMercBenzModels.Visible = False
             cmbDafModels.Visible = False
    
      End Select
    
    End If
    any help please

  2. #2
    Join Date
    Aug 2009
    Location
    NW USA
    Posts
    173

    Re: Combo Boxes

    Try:
    Code:
    If Not Me.CmbTruckTyp.SelectedItem is Nothing Then

  3. #3
    Join Date
    Feb 2009
    Posts
    192

    Re: Combo Boxes

    It didnt work!!

    I even tried

    Code:
    If CmbTruckTyp.SelectedIndex > -1 Then
    It never gives any error, however, both comboxes are visible regardless of "Daf" or "MEercedes-Benz" being selected..
    Any help pelase

  4. #4
    Join Date
    Aug 2009
    Location
    NW USA
    Posts
    173

    Re: Combo Boxes

    Like the other post, the ComboBox properties can be tricky. I would put a break on the If statement, hold the curser over CmbTruckTyp and find the property you want to test by looking at the values that actually exist.

  5. #5
    Join Date
    May 2002
    Location
    Boston
    Posts
    67

    Re: Combo Boxes

    Hi,

    This worked for me. What event are you using?

    Code:
    Private Sub CmbTruckTyp_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbTruckTyp.SelectedIndexChanged
    
    
            Try
    
                If Not Me.CmbTruckTyp.SelectedItem = Nothing Then
    
                    Select Case Me.CmbTruckTyp.SelectedItem.ToString
                        Case "Mercedes-Benz"
                            cmdMercBenzModels.Visible = True
                            cmbDafModels.Visible = False
                        Case "Daf"
                            cmdMercBenzModels.Visible = False
                            cmbDafModels.Visible = True
                        Case Else
                            cmdMercBenzModels.Visible = False
                            cmbDafModels.Visible = False
    
                    End Select
    
                End If
            Catch ex As Exception
    
            End Try
        End Sub

    Curt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured