Problem regarding tree view control fill alphabetLetter

simran

Member
Joined
Jul 7, 2006
Messages
8
Programming Experience
Beginner
Hi Friends

This is my first post here & I think that I will get positive response from all of you.
My problem is related to tree view control.

I can add child nodes in a tree view control.
My main problem is :
e.g

The root node is "alphabets"
Its child nodes are :
A
B
C
D
& so on until Z.

Now I want that when user clicks on any child node for example A then all the records in a table stored in MS-access databse starting with alphabet "A" must be displayed . Please help me in this matter.



Thanks


Thanks
 
i'm not sure about the treeview thing in this one. Seems a bit of a waste to me when a combobox would suffice. But anyway the problem your having isn't with the treeview it's with getting the values from the database? What have you got so far?, could you post some code? Have you got the dataadapter set up with all the appropriate SQL. A but more detail as to how far you have got would help us pin down exactly what part you are having problems with.
 
Hi

Till now I have made ony tree view control. not any coding. Actually I want coding for this.




(SIMRANJIT SINGH)
 
1st off it is odd if you have all the letters of alphabet but you are missing records from database that start with the odds letters. That's why you should 1st check what the start letters you need and then populate the treeview.
VB.NET:
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
[/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2]oledbcon.Open()
strSQL = "SELECT DISTINCT LEFT(FullName, 1) AS alphabetLetter FROM Users"
Reading(strSQL)
[/SIZE][SIZE=2][COLOR=#0000ff]While[/COLOR][/SIZE][SIZE=2] objRead.Read
tvAlphabet.Nodes.Add(objRead("alphabetLetter").ToString)
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]While
[/COLOR][/SIZE][SIZE=2]objRead.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception
MessageBox.Show(ex.Message)
[/SIZE][SIZE=2][COLOR=#0000ff]Finally
[/COLOR][/SIZE][SIZE=2]oledbcon.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]

then comes the easier part ... when you click/select certain letter in the treeview you will populate listbox with only records that start with the selected letter:

VB.NET:
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] tvAlphabet_AfterSelect([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Windows.Forms.TreeViewEventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] tvAlphabet.AfterSelect
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].lbMembers.Items.Clear()
[/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2]oledbcon.Open()
strSQL = "SELECT FullName AS members FROM Users WHERE FullName LIKE '" & [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].tvAlphabet.SelectedNode.Text & "%'"
Reading(strSQL)
[/SIZE][SIZE=2][COLOR=#0000ff]While[/COLOR][/SIZE][SIZE=2] objRead.Read
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].lbMembers.Items.Add(objRead("members").ToString)
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]While
[/COLOR][/SIZE][SIZE=2]objRead.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception
MessageBox.Show(ex.Message)
[/SIZE][SIZE=2][COLOR=#0000ff]Finally
[/COLOR][/SIZE][SIZE=2]oledbcon.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]

Just in case and to avoid confusing (you would of course wonder what is fullName or Users etc.) i added full working demo with the atached DB file too.

Regards ;)
 

Attachments

  • TreeViewAndDB.zip
    36.8 KB · Views: 25
Hi kulrom

Very Very Thank You man.

I have not seen your file that you have attached with your post yet, But I hope that this will solve my problem.


Once again Thanks
 
Back
Top