Manually add archived rows to dropdown if needed for selection

Posted on 2011-10-03
Last Modified: 2012-08-13
I have 2 subs. The first one populates the dropdown list. The second selects a value in the list.

Rows for the dropdown have been archived and don't get populated in the list. But if they are in the second sub to be selected, I need to be able to add that value back into the list for selection
Sub : 1 

        Dim sExternal As String = "SELECT * FROM tBOSTypes WHERE sCategory = @sCategory AND Archive = @Archive Order By sItem"
        Dim daExternal As New SqlClient.SqlDataAdapter(sExternal, myUtility.sqlConn)
        daExternal.SelectCommand.Parameters.AddWithValue("@sCategory", "External Wall Material")
        daExternal.SelectCommand.Parameters.AddWithValue("@Archive", False)
        Dim dtExternal As New DataTable
        Dim newCustomersRow As DataRow = dtExternal.NewRow()
        newCustomersRow("ID") = "0"
        newCustomersRow("sItem") = "Select Wall Type..."
        dtExternal.Rows.InsertAt(newCustomersRow, 0)
        cboExternal.DataSource = dtExternal
        cboExternal.DisplayMember = "sItem"
        cboExternal.ValueMember = "ID"

Sub : 2

        Dim sWall As String = "SELECT     tBOSItems.BOSTypeID, tBOSTypes.sCategory, tBOSTypes.sItem, tBOSItems.ProjectID, tBOSTypes.ID " & _
                           "FROM         tBOSTypes INNER JOIN " & _
                                       "tBOSItems ON tBOSTypes.ID = tBOSItems.BOSTypeID " & _
                           "WHERE     (tBOSItems.ProjectID = @ProjectID) AND sCategory = @Type"
        Dim daWall As New SqlClient.SqlCommand(sWall, myUtility.sqlConn)
        Dim dtWall As New DataTable
        daWall.Parameters.AddWithValue("@ProjectID", ContainerForm.ProjectID)
        daWall.Parameters.AddWithValue("@Type", "External Wall Material")
        WallID = daWall.ExecuteScalar
        cboExternal.SelectedValue = WallID

Open in new window

Question by:mgordon-spi
    1 Comment
    LVL 83

    Accepted Solution

    You can retrieve both the value and text and then use FindString/FindStringExact method to see if it exists in the list and add if not.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 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

    9 Experts available now in Live!

    Get 1:1 Help Now