473,382 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

MS ACCESS Drag and drop LISTVIEW to TREEVIEW help

66 64KB
Hi Team,

I am working on developing a reporting tool, user would like to show all the column headers in one list box and they would like to drag and drop the required fields in a treeview box. From Tree view box they will be filtering further more for the report.

This is similar to PIVOT TABLE functionality we use in excel. list of fieldnames, drag and drop option for ROWS and COLUMNS treeview box. An additional requirement is we will have the filter option with the checkboxes in Treeview, when the treeview loads the child value from query based on the fieldnames.


I have designed the LISTVIEW and took some code that helps me to construct the code to bring all the required table headers in listbox. Now I am having challenge to drag and drop the listview item to treeview and the treeview should load the child from a query (QryConsolidatedData) data.

Please could someone help me to drag and drop the listview item to treeview item and the tree view will immediately loads the childs for the dropped column.


So far my code goes like this
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3.     Dim strSQL As String
  4.     Dim nodSelected As Node
  5.     Dim lv As ListView
  6.     Set lv = Me.FColumns.Object
  7.     Dim adCmdText
  8.     adCmdText = 1
  9.     lv.ListItems.Clear
  10.     lv.ColumnHeaders.Clear
  11.  
  12. 'Update the listview box to show the positions held
  13.     strSQL = "SELECT BuildKey([ID]) AS ItemKey" & _
  14.              " ,[1FieldNames] as Columns" & _
  15.              " FROM [test]" & _
  16.              " WHERE BuildKey([1Required]) = TRUE"
  17.  
  18.  
  19. 'Build the list view
  20.             lv.ListItems.Clear
  21.             With CurrentProject.Connection
  22.             AddLVItems lv, .Execute(strSQL, , adCmdText), , , "2400,0"
  23.             '"2880,2160"
  24.             End With
  25.  
  26.  
  27. End Sub
  28.  
  29.  
  30.  
  31. Public Function BuildKey(ParamArray varKeyValues() As Variant) As String
  32. 'Joins the values of the passed varKeyValues to build a key.
  33. 'ALL Node keys MUST begin with a character.  For simplicity, this code
  34. 'uses a constant, tv_conKeyDesignator, for this character.  Also, for
  35. 'simplicity, all values used to build the key are separated by a constant,
  36. 'tv_conKeySeparator.  This methodology is used in order to create a consistent
  37. 'approach to building the nodes/keys on a tree view object.
  38. '
  39. 'NOTE: In order to maintain consistency, it is recommended that you
  40. 'set the PathSeparator property of the treeview object to be equivalent to
  41. 'tv_conKeySeparator
  42.  
  43.     Dim strTemp As String 'A 'working' string value
  44.  
  45.     'Build the key.
  46.     strTemp = tv_conKeyDesignator & Join(varKeyValues(), tv_conKeySeparator)
  47.  
  48.     'Return the result
  49.     BuildKey = Trim(strTemp)
  50.  
  51. End Function
  52.  
  53.  
  54.  
  55. Public Sub AddLVItems(lv As ListView, _
  56.                       rst As ADODB.Recordset, _
  57.                       Optional intKeyOrdinal As Integer = 0, _
  58.                       Optional intItemOrdinal As Integer = 1, _
  59.                       Optional strColumnWidths As String)
  60. 'Fills a List View object with the records from the passed rst
  61.  
  62.     Dim intTotCount As Integer
  63.     Dim fld As ADODB.Field
  64.     Dim colNewColumn As ColumnHeader 'A list view column header
  65.     Dim liNewRow As ListItem 'An Item in the list
  66.     Dim x As Long
  67.     Dim lngSubItem As Long
  68.     Dim strArrColumnWidths() As String
  69.  
  70.     'Clear the list view
  71.     lv.ListItems.Clear
  72.     lv.ColumnHeaders.Clear
  73.  
  74.     'Set Column Headers and set to report view
  75.     For Each fld In rst.Fields
  76.         If fld.Name <> rst(intKeyOrdinal).Name Then
  77.             Set colNewColumn = lv.ColumnHeaders.Add(, fld.Name, fld.Name)
  78.         End If
  79.     Next fld
  80.     lv.View = lvwReport
  81.  
  82.     'Set Column widths
  83.     If strColumnWidths = "" Then
  84.         'Do Nothing
  85.     Else
  86.         strArrColumnWidths = Split(strColumnWidths, lv_conCSVSeparator)
  87.         For x = LBound(strArrColumnWidths) To UBound(strArrColumnWidths) - 1
  88.                     lv.ColumnHeaders(x + 1).Width = CInt(strArrColumnWidths(x))
  89.         Next x
  90.     End If
  91.  
  92.     'Loop through the rst and fill the list view
  93.     Do Until rst.EOF
  94.  
  95.         'Add the row identifier ... which is the first field of the rst
  96.         Set liNewRow = lv.ListItems.Add(, rst(intKeyOrdinal).Value, CStr(rst(intItemOrdinal).Value))
  97.  
  98.         'Add the sub-items (other columns) of the row
  99.         For Each fld In rst.Fields
  100.             If fld.Name <> rst.Fields(intKeyOrdinal).Name _
  101.                And fld.Name <> rst.Fields(intItemOrdinal).Name Then
  102.                 lngSubItem = lngSubItem + 1
  103.                 liNewRow.SubItems(lngSubItem) = Nz(fld.Value, "")
  104.             End If
  105.         Next fld
  106.         lngSubItem = 0  'Clears the sub item index
  107.  
  108.         'Move to the next record
  109.         rst.MoveNext
  110.  
  111.     Loop
  112.  
  113. End Sub
Feb 25 '15 #1

✓ answered by Seth Schrock

Try looking through the video series by TheSmileyCoder. He has done extensive work on his tutorials and I'm sure that it will help you.

2 3534
Seth Schrock
2,965 Expert 2GB
Try looking through the video series by TheSmileyCoder. He has done extensive work on his tutorials and I'm sure that it will help you.
Feb 25 '15 #2
johny6685
66 64KB
Thank for the reply Seth. But unfortunately I do not have access to view the video in office, I will try to look at it once I reach home.

In the mean time please could you help me to code the treeview part.

I managed to move the selected data from List view to tree view. I am now stuck in to the Treeview part. How can I load the child nodes for all the field items I populated in the Treeview.

Please could someone help me to populate the child nodes from query for all fieldnames I have populated.
Feb 25 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: #Hai | last post by:
Hi, I have a TreeView control with hierarchy: A | - B // source | - C D // dest | - E Whenever draging B in to D, Item B is removed and B is added into D...
1
by: PeteCresswell | last post by:
I'm doing a metadata app. One of the screens is a TreeView of all the codes (i.e. allowed values) from various systems. Other screens list systems, databases, tables, and elements (i.e....
0
by: Dave harris | last post by:
Is anyone aware of any issues with Drag and Drop in a treeview having trouble scrolling past the top/bottom? For this particular control, scrolling down works about 50% of the time and is pretty...
4
by: Qingdong Z. | last post by:
I have a VS.NET windows application which use drag-drop feather. It works fine when application start, but stops working after application run one or two days. The application is related to Video...
1
by: pooja | last post by:
i need to implement drag and drop in treeview in VB. Kindly help. My treeview contains activities maintained using XML Files. Hopefully, Thanks.
1
by: Alan T | last post by:
I have a tree view on the left and a list view on the right. I will drag and drop from list view to treeview, and also drag drop tree node on the same tree view. How do I differentiate I drag...
2
by: shaznay2 | last post by:
I need some help! I'm trying to set up two drop down menus where the first displays the Department and the second displays the names of the printers found in the department. So far i have two...
2
by: bob | last post by:
Hi all, I have a treeview that has drag drop. Works well enough but... If you drag out of bounds of the treeview the nodrop icon comes on. Fair enough. But when I move back inside the treeview...
0
by: =?Utf-8?B?QW5kcmV3?= | last post by:
I have some code that I use to drag and drop from treeview to treeview, now I want to adapt the code to drag and drop from listview to treeview. I am having problems adapting the code nor can I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.