Solved

combo box selected value

Posted on 2006-07-21
5
312 Views
Last Modified: 2010-04-23
Hi, there,

I have this code that will get the selected value from the combo and put in the parameter.  The If statement will causes NullRefernceException ("obj ref not set to an instance of an obj") IF I typed a value which matchs one of the listed value, however, when I selected the value by mouse/keystroke, the code works fine. How can I change my if line to accomandate that goal?

            arParms(0) = New SqlParameter("@P1_CSR", SqlDbType.Int)
            If CType(cboCSR.SelectedItem, System.Data.DataRowView).Row("CSR").ToString = "" Then
                arParms(0).Value = DBNull.Value
            Else
                arParms(0).Value = cboCSR.SelectedValue
            End If
And here is how the combo got populated. By the way, the first row of the returned data are Null, Null.

            dsOptions = SqlHelper.ExecuteDataset(cn_str_QWright_Dev, CommandType.StoredProcedure, "CT_getCSR")
            dsOptions.Tables(0).TableName = "CSR"
            cboCSR.DataSource = dsOptions.Tables("CSR")
            cboCSR.DisplayMember = "CSR"
            cboCSR.ValueMember = "EmployeeID"

Thanks in advance!
0
Comment
Question by:ommer
  • 2
5 Comments
 
LVL 6

Expert Comment

by:manch
ID: 17158962
In such case u can use the Text property of the combo box or the SelectedIndex property of the compbo box

e.g. ( Replace ur if statement with )

If Trim(cboCSR.Text) = ""  Then
         arParms(0).Value = DBNull.Value
Else
        arParms(0).Value = cboCSR.Text
End If
0
 

Author Comment

by:ommer
ID: 17167863
Manch,

Thank you for your reply.

I need to account for both typing in value and selecting from the list. My original code could handle the selecting from list part.

Using your code to take care of the other half, I run into data type problem..

The parameter has to have a data type of Int. I guest I need a way to loop through my cbo.Items to find the one that eqauls to the typed in value, and make it the selected one.





0
 

Author Comment

by:ommer
ID: 17168151

Here is the one I got it to work. It turned out there is this FindString function I can use. The code block is little too messy than it needs to be.

            If Trim(cboCSR.Text) = "" Then
                If CType(cboCSR.SelectedItem, System.Data.DataRowView).Row("CSR").ToString = ""
                    arParms(0).Value = DBNull.Value
                Else
                    arParms(0).Value = cboCSR.SelectedValue
                End If
            Else
                cboCSR.SelectedIndex = cboCSR.FindString(cboCSR.Text)
                arParms(0).Value = cboCSR.SelectedValue
            End If
0
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
ID: 17206132
Closed, 125 points refunded.

GhostMod
Community Support Moderator
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

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

12 Experts available now in Live!

Get 1:1 Help Now