T
Troy
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.OleDbConnection = New
Data.OleDb.OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
OpenFileDialog1.FileName & ";Persist Security
Info=False;")
Dim DR As Data.OleDb.OleDbDataReader
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.OleDbCommand = New
Data.OleDb.OleDbCommand
(sqlNames, Conn)
' Clear Treeview Nodes
TreeView1.Nodes.Clear()
Try
Conn.Open()
DR = Cmd.ExecuteReader
If DR.HasRows = False Then
TreeView1.Nodes.Add("No Users on file")
TreeView1.ForeColor = Color.Red
NoUsers = True 'Boolean to tell other objects that
there are no users.
Else
TreeView1.ForeColor = 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(currentAlpha))
' Add a child TreeNode for each Customer
object in the current Alpha
Character.
If
UCase(Microsoft.VisualBasic.Left(DR("LastName1"), 1)) = currentAlpha
Then
sContactName = DR("Lastname1") & ", "
& DR("FirstName1") & " " &
DR("MiddleInitial1") & "."
System.Windows.Forms.Application.DoEvents()
TreeView1.Nodes(indx - 65).Nodes.Add(New
TreeNode(sContactName))
End If
Next
End While
DR.Close()
Conn.Close()
End If
Catch LX As Exception
MsgBox(LX.Message, MsgBoxStyle.Exclamation, "")
End Try
TreeView1.ExpandAll()
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.OleDbConnection = New
Data.OleDb.OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
OpenFileDialog1.FileName & ";Persist Security
Info=False;")
Dim DR As Data.OleDb.OleDbDataReader
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.OleDbCommand = New
Data.OleDb.OleDbCommand
(sqlNames, Conn)
' Clear Treeview Nodes
TreeView1.Nodes.Clear()
Try
Conn.Open()
DR = Cmd.ExecuteReader
If DR.HasRows = False Then
TreeView1.Nodes.Add("No Users on file")
TreeView1.ForeColor = Color.Red
NoUsers = True 'Boolean to tell other objects that
there are no users.
Else
TreeView1.ForeColor = 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(currentAlpha))
' Add a child TreeNode for each Customer
object in the current Alpha
Character.
If
UCase(Microsoft.VisualBasic.Left(DR("LastName1"), 1)) = currentAlpha
Then
sContactName = DR("Lastname1") & ", "
& DR("FirstName1") & " " &
DR("MiddleInitial1") & "."
System.Windows.Forms.Application.DoEvents()
TreeView1.Nodes(indx - 65).Nodes.Add(New
TreeNode(sContactName))
End If
Next
End While
DR.Close()
Conn.Close()
End If
Catch LX As Exception
MsgBox(LX.Message, MsgBoxStyle.Exclamation, "")
End Try
TreeView1.ExpandAll()