-
Jul 20th, 2011, 02:13 PM
#1
Thread Starter
New Member
Add items to second column of ListView Control?
I swiped some code to create a two column ListView control but am having some trouble editing some of the data. The code looks like this:
Dim itmX As ListItem ' Create a variable to add ListItem objects.
Dim clmX As ColumnHeader ' Create an object variable for the ColumnHeader object.
' Add ColumnHeaders.
Set clmX = ListView1.ColumnHeaders.Add(, , "Tag Name", ListView1.Width / 2)
Set clmX = ListView1.ColumnHeaders.Add(, , "Input #", ListView1.Width / 2)
ListView1.BorderStyle = ccFixedSingle ' Set BorderStyle property.
ListView1.View = lvwReport ' Set View property to Report.
For i = 1 To intDiDeviceNum
Private Sub Command1_Click()
' Add a main item
Set itmX = ListView1.ListItems.Add(i, , txtDiTagName.Text & i)
' Add two subitems for that item
itmX.SubItems(1) = "0"
Next i
When I run this, the ListView comes out the way I want it to but I can seemingly only edit the items in the first column but not the second column, they seem fixed. What I actually need is the opposite, where the first column is going to have fixed names from the above txtDiTagname.Text but I'll be able to edit the items in the second column for each row. Has anyone got any advice on how to do that?
Secondly, the plan is to concatonate the item name from Column 1 and Column 2 in each row. So, I also need to know how to extract the data from each column, in each row, to create a string. I'm planning on using a loop procedure but I'm not sure how to pull the text from each column section.
Thanks for your advice!
-
Jul 20th, 2011, 03:17 PM
#2
Re: Add items to second column of ListView Control?
To restrict Item editing change LabelEdit property to lvwManual; to edit any of the subitems you will need to implement floating textbox (you can probably find some samples if you search forum).
-
Jul 24th, 2011, 11:22 PM
#3
Lively Member
Re: Add items to second column of ListView Control?
i hope this change could help you
Code:
Private Sub Command1_Click()
Dim itmX As ListItem ' Create a variable to add ListItem objects.
Dim clmX As ColumnHeader ' Create an object variable for the ColumnHeader object.
' Add ColumnHeaders.
Set clmX = ListView1.ColumnHeaders.Add(, , "Tag Name", ListView1.Width / 2)
Set clmX = ListView1.ColumnHeaders.Add(, , "Input #", ListView1.Width / 2)
ListView1.BorderStyle = ccFixedSingle ' Set BorderStyle property.
ListView1.View = lvwReport ' Set View property to Report.
ListView1.GridLines = True
ListView1.FullRowSelect = True
ListView1.LabelEdit = lvwManual
For i = 1 To 3 'intDiDeviceNum
' Add a main item
Set itmX = ListView1.ListItems.Add(i, , txtDiTagName.Text & i)
' Add two subitems for that item
itmX.SubItems(1) = "0"
Next i
End Sub
Private Sub Command2_Click() 'control i add
'Click first which row you want to edit
'by default it change the first row
ListView1.SelectedItem.SubItems(1) = Text1.Text 'change the row in second column with the text from text1
End Sub
Private Sub Command3_Click() 'control i add
For i = 1 To ListView1.ListItems.Count
MsgBox ListView1.ListItems.Item(i).Text
MsgBox ListView1.ListItems.Item(i).SubItems(1)
Next i
End Sub
Private Sub Form_Load()
Command1.Caption = "Populate data"
Command2.Caption = "Edit"
Command3.Caption = "Pull Text Loop"
End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|