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:
The load of the first list box is as follows:
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: