Hello,


can you help me please, how can be my newly added data to be selected in my listview after i clicked my Add button.Please help me.

Thank you in advance hoping for your positive response.

here is my code.

Private Sub cmdadd_Click()
 
Dim Objlist as ListItem
 

sql = "INSERT INTO Customer(id,Name,familyName,Address) VALUES('" & lngId & "','" & txtname & "', '" & txtfamilyname & "','" & txtaddress & "')"
con.Execute sql
 
GetData lvwIP

//This Three Lines is not working 
Set Objlist = lvwIP.ListItems.Add(, , txtname.Text)
  Newlist Objlist
   Set lvwIP.SelectedItem = Objlist
 //I have problem in here,It will not select the newly added data
End Sub
 
Private Sub Newlist(list As ListItem)
  
  With list
    .Text = txtname.Text
    .SubItems(1) = txtfamilyname.Text
    .SubItems(2) = txtaddress.Text
   End With
End Sub

See if this helps.

Actually when you add data it added in the last.
So, you just simply select the last data on listview :

Private Sub cmdadd_Click()

sql = "INSERT INTO Customer(id,Name,familyName,Address) VALUES('" & lngId & "','" & txtname & "', '" & txtfamilyname & "','" & txtaddress & "')"
con.Execute sql
 
GetData lvwIP

' Select a newly data added start here
ListView1.ListItems(ListView1.ListItems.Count).Selected = True ' select the last data on list view and set it as true
ListView1.SetFocus ' set focus on listview
ListView1.FullRowSelect = True ' full row selected

End Sub

But if you don't sure if data not added on last index then use this following code :

Private Sub cmdadd_Click()
' Declared variable
Dim itm As ListItem 
Dim strSearch As String
Dim x As Integer
 
sql = "INSERT INTO Customer(id,Name,familyName,Address) VALUES('" & lngId & "','" & txtname & "', '" & txtfamilyname & "','" & txtaddress & "')"
con.Execute sql
 
GetData lvwIP

' Select a newly data added start here
strSearch = Text1.Text

For Each itm In ListView1.ListItems ' search for all list item on listview
    If itm.Text = strSearch Then ' assign if item = strsearch
        x = itm.Index ' get the index of founded item
        ListView1.ListItems(x).Selected = True ' Highlight the row
        ListView1.SetFocus ' set focus on listview
    End If
Next
ListView1.FullRowSelect = True ' full row selected

End Sub

Edited 5 Years Ago by Jx_Man: n/a

See if this helps.

Actually when you add data it added in the last.
So, you just simply select the last data on listview :

Private Sub cmdadd_Click()

sql = "INSERT INTO Customer(id,Name,familyName,Address) VALUES('" & lngId & "','" & txtname & "', '" & txtfamilyname & "','" & txtaddress & "')"
con.Execute sql
 
GetData lvwIP

' Select a newly data added start here
ListView1.ListItems(ListView1.ListItems.Count).Selected = True ' select the last data on list view and set it as true
ListView1.SetFocus ' set focus on listview
ListView1.FullRowSelect = True ' full row selected

End Sub

But if you don't sure if data not added on last index then use this following code :

Private Sub cmdadd_Click()
' Declared variable
Dim itm As ListItem 
Dim strSearch As String
Dim x As Integer
 
sql = "INSERT INTO Customer(id,Name,familyName,Address) VALUES('" & lngId & "','" & txtname & "', '" & txtfamilyname & "','" & txtaddress & "')"
con.Execute sql
 
GetData lvwIP

' Select a newly data added start here
strSearch = Text1.Text

For Each itm In ListView1.ListItems ' search for all list item on listview
    If itm.Text = strSearch Then ' assign if item = strsearch
        x = itm.Index ' get the index of founded item
        ListView1.ListItems(x).Selected = True ' Highlight the row
        ListView1.SetFocus ' set focus on listview
    End If
Next
ListView1.FullRowSelect = True ' full row selected

End Sub

Hello sir,

Thank you for the reply,Okay I will try this sir and i will write again if i have doubt.more power to you sir.

See if this helps.

Actually when you add data it added in the last.
So, you just simply select the last data on listview :

Private Sub cmdadd_Click()

sql = "INSERT INTO Customer(id,Name,familyName,Address) VALUES('" & lngId & "','" & txtname & "', '" & txtfamilyname & "','" & txtaddress & "')"
con.Execute sql
 
GetData lvwIP

' Select a newly data added start here
ListView1.ListItems(ListView1.ListItems.Count).Selected = True ' select the last data on list view and set it as true
ListView1.SetFocus ' set focus on listview
ListView1.FullRowSelect = True ' full row selected

End Sub

But if you don't sure if data not added on last index then use this following code :

Private Sub cmdadd_Click()
' Declared variable
Dim itm As ListItem 
Dim strSearch As String
Dim x As Integer
 
sql = "INSERT INTO Customer(id,Name,familyName,Address) VALUES('" & lngId & "','" & txtname & "', '" & txtfamilyname & "','" & txtaddress & "')"
con.Execute sql
 
GetData lvwIP

' Select a newly data added start here
strSearch = Text1.Text

For Each itm In ListView1.ListItems ' search for all list item on listview
    If itm.Text = strSearch Then ' assign if item = strsearch
        x = itm.Index ' get the index of founded item
        ListView1.ListItems(x).Selected = True ' Highlight the row
        ListView1.SetFocus ' set focus on listview
    End If
Next
ListView1.FullRowSelect = True ' full row selected

End Sub

Hello sir,it's working thank you for this. I used this code

sql = "INSERT INTO Customer(id,Name,familyName,Address) VALUES('" & lngId & "','" & txtname & "', '" & txtfamilyname & "','" & txtaddress & "')"
con.Execute sql
 
GetData lvwIP

' Select a newly data added start here
ListView1.ListItems(ListView1.ListItems.Count).Selected = True ' select the last data on list view and set it as true
ListView1.SetFocus ' set focus on listview

by the way sir i removed this one line but
it's still working and it makes highlight to my newly added data.please correct me if i am worong.

ListView1.FullRowSelect = True ' full row selected

Thank you in advance and i am hoping for your positive response.

Hi,

it highlights because the property of the listbox is set to true in the fullrowselect property. you can change it to true or false in the properties window in vb.

Hi,

it highlights because the property of the listbox is set to true in the fullrowselect property. you can change it to true or false in the properties window in vb.

Hi sir, thank you for the reply,yes i found and it set to true,by the way how can i make my listview that remains higlight when i select the data on it.Because if i will set the cursor to the Nametextfield the highlight on my listview will be gone and this could make me problem in my update.

example if have this list on my listiew

First Name Family Name Address

Jemz Gimz Australia
Carl MaHn Singapore//here will be higlight
Fred Kenusha Japan


My problem now if i will set the cursor to the Nametextfield

Name __________//textfield here,...the higlight in Carl mahn Singapore will be gone

can you help me please how can i make the higlight remain if i will set the cursor to the textfield.

Thank you in advance and I am hoping for your positive response

Lets keep originally question of this thread. if this thread already answered please make it solved and if you have a new question please make a new thread. it will help another member when they search a same thread.

Thank you :)

For your question :

can you help me please how can i make the higlight remain if i will set the cursor to the textfield.

Set the HideSelection property of the ListView control to false..

Edited 5 Years Ago by Jx_Man: n/a

Lets keep originally question of this thread. if this thread already answered please make it solved and if you have a new question please make a new thread. it will help another member when they search a same thread.

Thank you :)

For your question :

Set the HideSelection property of the ListView control to false..

Hello sir thank you for the reply.Okay sir i will marked this solved.I apologize.I will make my new thread.

Hello sir thank you for the reply.Okay sir i will marked this solved.I apologize.I will make my new thread.

Thank you :)
Happy coding.

This question has already been answered. Start a new discussion instead.