?
Solved

combo box selected value

Posted on 2006-07-21
5
Medium Priority
?
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

800 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