Code Around Needed

tcl4p

Well-known member
Joined
Feb 29, 2008
Messages
48
Programming Experience
1-3
I have a list box that when an item is selected loads data into a second list box. The problem is the second list box has code behind it in the SelectedIndexChange and when the data is loaded it executes as if a value was selected. I was able to eliminate the selection by setting the index to -1, but is there any way other then setting some variable on load to identify the load to prevent/Bypass the selection event from happening?

The code for the second list box is:
VB.NET:
 Me.clsTask.tID = Me.lbTasksSelected.SelectedValue
 Me.txtTaskInfo.Text = clsTask.GetTaskInfoByID
 If Me.txtTaskInfo.Text.Trim.Length = 0 Then
    Me.lblMsg.Text = "No Task Information Available"
 Else
     Me.lblMsg.Text = vbNullString
 End If

The load of the first list box is as follows:
VB.NET:
  Private Sub LoadTaskGroups()
        Dim reader As SqlDataReader
        Dim dt As New DataTable

        Try
            If Not IsNothing(Me.lbGroup.DataSource) Then
                Me.lbGroup.DataSource = Nothing
            End If
            Me.lbGroup.Items.Clear()
            reader = clsTask.GetTaskGroups
            Dim tb As New DataTable
            tb.Load(reader)
            Me.lbGroup.DisplayMember = "TaskGroup"
            Me.lbGroup.ValueMember = "tgID"
            Me.lbGroup.DataSource = tb
            reader.Close()
            Me.lbGroup.SelectedIndex = -1
           
        Catch ex As Exception
            MsgBox(ex.Message)

        End Try
    End Sub
 
Last edited by a moderator:
Er.. use DataRelations ? There's no need to ahve a db, jsut a typed dataset with a Parent table, a child table and a relation between them. Two listboxes bound through Bindingsources, the parent bindingsource binds straight to the data, the child binds to the relationship exposed by the parent

Its all very simple and takes about 2 minutes to arrange
 
Back
Top