Question : How do I get the value Member from a Multi-select List box in VB.NET

I have a list box on a VB.NET form that is in multi select mode.

Users can select 1 or more items from the list and click a button to process those items.

How do I get the value item from the list box - which is the primary key of the underlying dataset - rather than the text item of the list box - so that the selected rows can be further processed.

The code for the dataset and list box population are detailed below


Thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
Sub sbLoadBackUpList()

        Dim SQLcnn As New clsConnectivity()
        Dim objCnn As SqlConnection = New SqlConnection(SQLcnn.cnn.ToString)
        Dim objDataAdapter As New SqlDataAdapter()
        Dim objGradings As DataSet = New DataSet()

        Try
            objDataAdapter.SelectCommand = New SqlCommand
            objDataAdapter.SelectCommand.Connection = objCnn
            objDataAdapter.SelectCommand.CommandText = "SELECT tblGradingEvents.GRADING_ID, tblVenues.VENUE_NM + ' on ' + CONVERT(VARCHAR(10),tblGradingEvents.GR_DATE , 103) AS [Grading Event] FROM tblGradingEvents LEFT OUTER JOIN tblVenues ON tblGradingEvents.VENUE_ID = tblVenues.VENUE_ID ORDER BY GR_DATE desc"

objDataAdapter.SelectCommand.CommandType = CommandType.Text

            objDataAdapter.Fill(objGradings, "Gradings")
            objDataAdapter = Nothing

            With lstGradingsToMerge
                .DataSource = objGradings.Tables("Gradings")
                .DisplayMember = "Grading Event"
                .ValueMember = "GRADING_ID"
            End With


        Catch ex As Exception
            '-----------------
            'Data load errors

            Err.Clear()

            MsgBox(Err.Description, MsgBoxStyle.Information, "System Error")
        End Try
    End Sub

Answer : How do I get the value Member from a Multi-select List box in VB.NET

Hi DavidHannen;

Something like this:

For Each id As Integer in gradingID
    ' For each iteration the value in id is the Value Item for one of the selected value
    ' Do processing using the Primary Key id here.
Next

Fernando
Random Solutions  
 
programming4us programming4us