hi,

How to code, if let say i want only 10 records to inserted in listview.
By mean listview only can accept 10 records.
please guide

thank you

If Not ListView1.Items.Count = 10 Then
            ListView1.Items.Add("new item")
        End If

hi,

i have tried your code but its still accept more than 10 records. My code is like this :
nTotlistrec = ListView1.Items.Count
nTotlistrec = 10
If nTotlistrec <= 10 Then
MsgBox("you can only pay 10 bills per transaction")
End If

its prompt the msgbox but it still accept bill no.11 and so on.......
How can i make it after the msgbox prompt it would be able to show only 10 records and the excessive to be deleted form the text file(temporary text file).
By mean it shouldnt accept record number 11.

please help

hi,
i have tried your code but its still accept more than 10 records...

I seriously doubt that.

About your code, try it in a new project.

Public Class Form1
    '// Pre-requisites: 1 ListView, 1 Button.
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListView1.View = View.List
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim nTotlistrec As Integer = ListView1.Items.Count
        If nTotlistrec < 10 Then '// check if less than 10.
            ListView1.Items.Add("new item" & ListView1.Items.Count + 1)
        Else
            MsgBox("you can only pay 10 bills per transaction")
        End If
    End Sub
End Class

You had <= instead of just <, which would add an extra item.

hi,

its working in new project but it doesnt work in my project even i put the code on a button click.The button in form1 and listview is in form2
I put this code when button click on frmPaymentSummary but when the button click it doesn prompt anything and still accepting the records.

Dim nTotlistrec As Integer = frmPaymentSummary.ListView1.Items.Count
If nTotlistrec < 10 Then '// check if less than 10.
frmPaymentSummary.ListView1.Items.Add(frmPaymentSummary.ListView1.Items.Count + 1)
Else
MsgBox("you can only pay 10 bills per transaction")
End If


Do you have any idea on it.

It has to do something with the way your code is setup.

You can post your code here for the 2 Forms OR if you want to keep it confidential you can send the code to me in a private message.

hi,

i have send my codes thru private message. Have you got it.

hi,

i have send my codes thru private message. Have you got it.

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.