Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to edit a list view control

Status
Not open for further replies.

JawwadLone

Programmer
Mar 17, 2004
57
PK
Is there any way, we can edit value in subitem of a listview control, without using another form?

 
Hi JawwadLone - Welcome to Tek-Tips.

To get the best from the forum make sure you read faq222-2244 carefully.

If I understand your question you can just set the subitem value directly.

ListView1.SelectedItem.SubItems(1) = "Testing"

If not, can you clarify what you want to do?


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
I think what he is trying to achieve is that the user can click in a sub item, and then edit it.

For this you need to place a textbox over the subitem, and then when the user hits return, use Johnwm line of code to make the contenbts of the subitem the same as the text box.

Is this what you were after?

BB
 
Thank you Mr. BiggerBrother. you understood the problem correctly. I am using visual basic 6.0. In my form i want to get all the products from a table and want to add their related quantity in stock. I have done it, for individual product through a form using textboxes. Now i want to do it all at once from the same form. I tried it by using ListView control but unfortunately didn't managed to get through. Now u have given the idea of text box on the listview control. Can you kindly describe it in little detail. Thank you for ur nice reply.
 
I have have managed the problem through the following code. Now all i need to know is how to move the textbox on the listview control, because i can't see any left,width or top properties of subitems of listview control.

Code: (This code is written on KeyDown event of text box)
=====

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If (KeyCode >= 48 And KeyCode <= 56) Or KeyCode = 45 Then Exit Sub

If KeyCode = 13 Or KeyCode = 40 Then 'Down Arrow
ls.SubItems(2) = Val(Text1.Text)
If rec < lsCount Then
rec = rec + 1
Set ls = ListView1.ListItems.Item(rec)
Text1.Text = ls.SubItems(2)
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
ElseIf KeyCode = 38 Then 'Up Arrow
ls.SubItems(2) = Val(Text1.Text)
If rec > 1 Then
rec = rec - 1
Set ls = ListView1.ListItems.Item(rec)
Text1.Text = ls.SubItems(2)
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
End If
End Sub



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top