I've almost got this the way I want it. I'm loading my customer names
into a treeview control. My problem is I'm repeating my root nodes. I
know it's something to do with my loop structure but My eyes are
crossing from it can someone help me get this organised lol. here's
my code.
Private Sub updateTree()
Dim Conn As Data.OleDb.OleD bConnection = New
Data.OleDb.OleD bConnection
("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=" & _
OpenFileDialog1 .FileName & ";Persist Security
Info=False;")
Dim DR As Data.OleDb.OleD bDataReader
Dim indx As Short
Dim NoUsers As Boolean
Dim sqlNames As String
Dim currentAlpha As String
Dim sContactName As String
sqlNames = "SELECT ContactID, LastName1, FirstName1,
MiddleInitial1 "
sqlNames = sqlNames & "FROM Contact ORDER BY"
sqlNames = sqlNames & " LastName1, FirstName1,
MiddleInitial1 "
Dim Cmd As Data.OleDb.OleD bCommand = New
Data.OleDb.OleD bCommand
(sqlNames, Conn)
' Clear Treeview Nodes
TreeView1.Nodes .Clear()
Try
Conn.Open()
DR = Cmd.ExecuteRead er
If DR.HasRows = False Then
TreeView1.Nodes .Add("No Users on file")
TreeView1.ForeC olor = Color.Red
NoUsers = True 'Boolean to tell other objects that
there are no users.
Else
TreeView1.ForeC olor = Color.Black
NoUsers = False 'Boolean to tell other objects that
there are users. End If
While DR.Read
For indx = Asc("A") To Asc("Z")
currentAlpha = Chr(indx)
TreeView1.Nodes .Add(New
TreeNode(curren tAlpha))
' Add a child TreeNode for each Customer
object in the current Alpha
Character.
If
UCase(Microsoft .VisualBasic.Le ft(DR("LastName 1"), 1)) = currentAlpha
Then
sContactName = DR("Lastname1" ) & ", "
& DR("FirstName1" ) & " " &
DR("MiddleIniti al1") & "."
System.Windows. Forms.Applicati on.DoEvents()
TreeView1.Nodes (indx - 65).Nodes.Add(N ew
TreeNode(sConta ctName))
End If
Next
End While
DR.Close()
Conn.Close()
End If
Catch LX As Exception
MsgBox(LX.Messa ge, MsgBoxStyle.Exc lamation, "")
End Try
TreeView1.Expan dAll()
*---------------------------------*
Posted at: http://www.GroupSrv.com
*---------------------------------*
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com