Hi,

I am facing prblm in selecting compbobox...

I have a 2 combobox...cboxSelunits and cboxseldept

In selected index change of Cbxunit i am filling CbxDept.....

and in selected index change of cboxseldept i need to populate the treeview

-----------------------------------------------------------------------

Private Sub cboxSelunits_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboxSelunits.SelectedIndexChanged
Try

If con.State = ConnectionState.Open Then
con.Close()
End If
con.Open()
_da1 = New SqlDataAdapter("select departmentname from department where unitid='" & unitid & "' ", con)
_dt = New DataTable
_da1.Fill(_dt)
With cboxseldept
.DataSource = _dt
.DisplayMember = "departmentname"
.SelectedIndex = -1
End With
cboxseldept.Visible = True
lbldept.Visible = True
con.Close()
Catch ex As Exception
con.Close()
Finally
con.Close()
End Try
End Sub

------------------------------------------------------------------------


Private Sub cboxseldept_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboxseldept.SelectedIndexChanged

PopulateTree()

End Sub


--------------------------------------------------

But error i am facing is when i am selecting cboxselUnits ifself cboxseldept is getting filled as well as treeview is getting populated......

You rproblem is here:
With cboxseldept
.SelectedIndex = -1

you are changing the index whcih will fire the SelectedIndexChanged Event.

To stop the tree populating incorrectly, alter the SelectedIndexChanged event to this:

If cboxseldept.SelectedIndex > -1 Then PopulateTree()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.