This sample code displays employee name in the treeview control from the emp table of Scott schema in oracle database.
To start with
Select Microsoft windows common controls 6.0 (SP6) from components
Add a TreeView and a ListView control to the form.
Add this sample code to the form
========================== - Dim con As New ADODB.Connection
-
Dim rs As New ADODB.Recordset
-
Dim rs1 As New ADODB.Recordset
-
-
Private Sub Form_Load()
-
con.Open "Provider=OraOLEDB.Oracle.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=das"
-
-
call TREE
-
End Sub
-
-
Public Sub TREE()
-
tv1.Visible = False
-
tv1.Nodes.Clear
-
tv1.Visible = True
-
Dim scontactname As String
-
Dim currentalpha As String
-
-
rs1.Open "select * from emp order by ename", con, adOpenDynamic, adLockOptimistic
-
If (rs1.RecordCount > 0) Then
-
rs1.MoveFirst
-
End If
-
For indx = Asc("A") To Asc("Z")
-
currentalpha = Chr(indx)
-
Set contactnode = tv1.Nodes.Add(, , currentalpha, currentalpha)
-
If (Not rs1.EOF) Then
-
Do While UCase(Left(rs1!ename, 1)) = currentalpha
-
With rs1
-
If (Not IsNull(!ename)) Then
-
scontactname = !ename
-
End If
-
End With
-
DoEvents
-
Set contactnode = tv1.Nodes.Add(currentalpha, tvwChild, rs1!ename, scontactname)
-
rs1.MoveNext
-
If (rs1.EOF) Then
-
Exit Do
-
End If
-
Loop
-
End If
-
Next
-
-
rs1.Close
-
DoEvents
-
End Sub
-
To display the details of the record as selected from the Treeview control.
Add the column headers in the listview from property pallet as the field name from the table if desired.
Add the following sample code
======================== -
Private Sub tv1_NodeClick(ByVal Node As MSComctlLib.Node)
-
LV1.ListItems.Clear
-
rs.Open "select * from EMP where ENAME = '" & tv1.SelectedItem.Key & "'", con, adOpenDynamic, adLockOptimistic
-
-
Dim li1 As ListItem
-
Set li1 = LV1.ListItems.Add()
-
If Not rs.EOF Then
-
-
If IsNull(rs(0)) Then
-
li1.Text = ""
-
Else
-
li1.Text = rs(0)
-
End If
-
-
If IsNull(rs(1)) Then
-
LV1.ListItems(1).ListSubItems.Add , , ""
-
Else
-
LV1.ListItems(1).ListSubItems.Add , , rs(1)
-
End If
-
-
If IsNull(rs(2)) Then
-
LV1.ListItems(1).ListSubItems.Add , , ""
-
Else
-
LV1.ListItems(1).ListSubItems.Add , , rs(2)
-
End If
-
-
If IsNull(rs(3)) Then
-
LV1.ListItems(1).ListSubItems.Add , , ""
-
Else
-
LV1.ListItems(1).ListSubItems.Add , , rs(3)
-
End If
-
If IsNull(rs(4)) Then
-
LV1.ListItems(1).ListSubItems.Add , , ""
-
Else
-
LV1.ListItems(1).ListSubItems.Add , , rs(4)
-
End If
-
If IsNull(rs(5)) Then
-
LV1.ListItems(1).ListSubItems.Add , , ""
-
Else
-
LV1.ListItems(1).ListSubItems.Add , , rs(5)
-
End If
-
If IsNull(rs(6)) Then
-
LV1.ListItems(1).ListSubItems.Add , , ""
-
Else
-
LV1.ListItems(1).ListSubItems.Add , , rs(6)
-
End If
-
If IsNull(rs(7)) Then
-
LV1.ListItems(1).ListSubItems.Add , , ""
-
Else
-
LV1.ListItems(1).ListSubItems.Add , , rs(7)
-
End If
-
-
End If
-
rs.Close
-
End Sub
-
0 16249 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Angelina |
last post by:
Hi,
I wanted to add a few items to my listview control. The
values of these will be obtained from other controls on
my interface. When the user clicks the select button,
they will need to be...
|
by: Eva |
last post by:
Hi,
I wanted to know how i can enter values into a specific
column of a listview. I have tried the following code but
this seems to enter all my values into the first column!!!
Can anyone...
|
by: Daisy |
last post by:
I'm writing a NewsReader (seemed like a decent project to start learning
with), and want threading like in OE.
I've got a treeview and a listview. On Expand/Contract on the listview, I
spin...
|
by: cybertof |
last post by:
Hello,
Is there a solution to the following problem :
When filling a listview (30 columns) with around 5000 items, it can take
easily 10 sec for the listview to be filled.
I have used...
|
by: Holmes |
last post by:
Hello
Ran into a bit of a problem here and have now exhausted my resources to getting this working
What I am trying to do is load and show a simple vb form with a listbox in it
Dim...
|
by: Ash Phillips |
last post by:
Hi Everyone,
I have this program I wrote in VB6 for family use. It's a DVD Database just
for me to keep track of them cause I have so many lol.
In VB6, I could add items to the ListView in...
|
by: James L |
last post by:
I have 2 different forms that contain treeviews and listviews. The former is
used to populate the latter.
For some reason the control randomly lose the images. So you cannot tell in
the...
|
by: Beginner |
last post by:
Hi,
I'm trying to populate a TreeView from an existing and filled in
ListView (lvwBuild). lvwBuild is a basic two column listview which can
have any number of rows. I would like the first...
|
by: ChinChin |
last post by:
Hi,
How to make the nodes (Tree View control) referring to the files stored in my local directory (e.g.: drive C) and display the file details in List View control?
Thanks.
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |