Hello,


Please help me, how can i populate or display my newly added list in the listview, if i will click my addbutton.can you please help me.

Thank you in advance and I am hoping for your positiver response.

do you have any code? how many sub items?

Edited 5 Years Ago by jlego: i gave code for .net.

Hello,


Please help me, how can i populate or display my newly added list in the listview, if i will click my addbutton.can you please help me.

Thank you in advance and I am hoping for your positiver response.

Hi,
Are you can display data on listview?
What database are you using?

Hi,
Are you can display data on listview?
What database are you using?

hello sir thank you for the reply,I'm using ms access.Please help me sir thank you in advance and I am hoping for your positive response.

do you have any code? how many sub items?

Hi sir, I have 3 column headers only and i am using the ms access.can you help me please.

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

How far you doing this?
Post your code, we try to help :)

Hello sir here is my code, My problem is that i don't know how to display in the listview after i clicked the add button.can you help me please thank you in advance and I am hoping for your positive response.

Private Sub cmdadd_Click()

 Dim lngId As Long
 
 lngId = GenNextID
  

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

End Sub

Private Sub cmdexit_Click()
Unload Me
End Sub

Private Sub Form_Load()
 ConnectToDB
 Call ColumnName(lvwIP, "Name", 40, "Family Name", 30, " Address", 40)
End Sub
Private Sub ColumnName(LSV As listview, ParamArray listview())
 Dim i, width
 
 LSV.View = lvwReport
 
 width = LSV.width - 80
 
 With LSV.ColumnHeaders
   .Clear
   
   For i = 0 To UBound(listview) - 1 Step 2
    .Add , , listview(i), (listview(i + 1) * width) / 100
    Next i
   End With
   
End Sub
Public Function GenNextID() As Long

sql = "select max(gen_id)as MaxID from Customer"
Set ip_rs = New adodb.Recordset
ip_rs.Open sql, con, adOpenDynamic, adLockPessimistic


If ip_rs.EOF Then
  GenNextID = 1
  ElseIf IsNull(ip_rs!MaxID) Then
    GenNextID = 1
Else
 GenNextID = ip_rs!MaxID + 1
End If

ip_rs.Close

End Function

You have procedure to display it..ColumnName..just call after insert data.

Private Sub cmdadd_Click()

 Dim lngId As Long
 
 lngId = GenNextID
  

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

Call ColumnName(lvwIP, "Name", 40, "Family Name", 30, " Address", 40) ' Call here to update listview

End Sub

You have procedure to display it..ColumnName..just call after insert data.

Private Sub cmdadd_Click()

 Dim lngId As Long
 
 lngId = GenNextID
  

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

Call ColumnName(lvwIP, "Name", 40, "Family Name", 30, " Address", 40) ' Call here to update listview
End Sub

hello sir thank you for the reply. Sir I am confuse I don't know how to Display in the listview sir.Can you help me please.

Thank you in advance hoping for your positive response.

Try this following code to display data from access :

Private Sub GetData(LSV As ListView)
Call ColumnName(lvwIP, "Name", 40, "Family Name", 30, " Address", 40)
            
    Set rs = New ADODB.Recordset
    rs.Open "SELECT * from Customer", Con, adOpenStatic, adLockOptimistic
    
    LSV.ListItems.Clear
    
    While Not rs.EOF
        Set View = LSV.ListItems.Add
        View.Text = rs!Name
        View.SubItems(1) = rs!familyName
        View.SubItems(2) = rs!Address
       
        rs.MoveNext
    Wend
    rs.Close
    
End Sub

Call GetData after insert data :

Private Sub cmdadd_Click()

 Dim lngId As Long
 
 lngId = GenNextID
  

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

GetData lvwIP ' Call here to update listview

End Sub

Try this following code to display data from access :

Private Sub GetData(LSV As ListView)
Call ColumnName(lvwIP, "Name", 40, "Family Name", 30, " Address", 40)
            
    Set rs = New ADODB.Recordset
    rs.Open "SELECT * from Customer", Con, adOpenStatic, adLockOptimistic
    
    LSV.ListItems.Clear
    
    While Not rs.EOF
        Set View = LSV.ListItems.Add
        View.Text = rs!Name
        View.SubItems(1) = rs!familyName
        View.SubItems(2) = rs!Address
       
        rs.MoveNext
    Wend
    rs.Close
    
End Sub

Call GetData after insert data :

Private Sub cmdadd_Click()

 Dim lngId As Long
 
 lngId = GenNextID
  

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

GetData lvwIP ' Call here to update listview

End Sub

hello sir, i have problem it get an error "variable not define" (View)

The view sir will get an error.Please help me sir.

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

Sorry for that, my Bad.
Declare view as list item :

Dim view As ListItem

Hello sir, It works thank you for this.by the way sir.why is that you use adOpenstatic?
Please help me sir to enligthen my mind.

Thank you in advance hoping for your positive response.

see this site for adOpenstatic explaination
Don't Forget to mark this thread as solved :)

yeah Thank you so much sir.Thank you also for the links.

Try this following code to display data from access :

Private Sub GetData(LSV As ListView)
Call ColumnName(lvwIP, "Name", 40, "Family Name", 30, " Address", 40)
            
    Set rs = New ADODB.Recordset
    rs.Open "SELECT * from Customer", Con, adOpenStatic, adLockOptimistic
    
    LSV.ListItems.Clear
    
    While Not rs.EOF
        Set View = LSV.ListItems.Add
        View.Text = rs!Name
        View.SubItems(1) = rs!familyName
        View.SubItems(2) = rs!Address
       
        rs.MoveNext
    Wend
    rs.Close
    
End Sub

Call GetData after insert data :

Private Sub cmdadd_Click()

 Dim lngId As Long
 
 lngId = GenNextID
  

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

GetData lvwIP ' Call here to update listview

End Sub

Hi sir, I forgot to ask with you this.what if sir i have millions of data. Does my program become slow?because it will display the whole data in my listview.please help me sir i am confuse.

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

Try this following code to display data from access :

Private Sub GetData(LSV As ListView)
Call ColumnName(lvwIP, "Name", 40, "Family Name", 30, " Address", 40)
            
    Set rs = New ADODB.Recordset
    rs.Open "SELECT * from Customer", Con, adOpenStatic, adLockOptimistic
    
    LSV.ListItems.Clear
    
    While Not rs.EOF
        Set View = LSV.ListItems.Add
        View.Text = rs!Name
        View.SubItems(1) = rs!familyName
        View.SubItems(2) = rs!Address
       
        rs.MoveNext
    Wend
    rs.Close
    
End Sub

Call GetData after insert data :

Private Sub cmdadd_Click()

 Dim lngId As Long
 
 lngId = GenNextID
  

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

GetData lvwIP ' Call here to update listview

End Sub

Hello sir.I returned back with this thread because there is something bothering in my mind and i am confuse with the code sir.My question is that, is this code safe for millions of data and then loading it in my listview.can you please help me to enligthen my mind sir.please...thank you in advance and i'm hoping for your positive response.

My question is that, is this code safe for millions of data and then loading it in my listview.

I think the code is safe.
But it consume many times to load a millions data.
I think its not good to displaying all entire data in one time.

I think the code is safe.
But it consume many times to load a millions data.
I think its not good to displaying all entire data in one time.

Hi sir thank you for the reply, sir can you please help me what should i do.What is the best thing to do if i have millions of data.please help me sir.Thank you in advance and i am hoping for your positive response.

What is the best thing to do if i have millions of data.please help me sir

Don't display the entire data but display it separately.
You can use navigate button..
I recommended you to make a new spesific thread to asking about displaying a millions data. There are many members will give a good answer.

Don't display the entire data but display it separately.
You can use navigate button..
I recommended you to make a new spesific thread to asking about displaying a millions data. There are many members will give a good answer.

hello sir thank you for the reply...okay sir,i already posted the thread please help me on this.here is the link

http://www.daniweb.com/software-development/visual-basic-4-5-6/threads/363681

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

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