Click here to Skip to main content
15,900,592 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In my C# Windows Form MyForm, there's one ListView control listView1 in the
MyForm.
The ListViewItem in the listView1 MATCHING EXACTLY the data in a SQL Server
database table Customer.
e.g.,
Serial ID Name
----------------------------
1 123 John
2 125 Marry
3 201 Leo
4 305 Britney

If we DELETE the first Row [1,123, John] in the listView1,
How we will reasign the Serial for the rest Rows.

the result:
Serial ID Name
----------------------------
1 125 Marry
2 201 Leo
3 305 Britney


Can Any One Give Nice Idea For Reasign the listview Serial No?
Posted
Comments
KalaiPondy 14-Feb-13 1:43am    
I think you didn't get what I was trying to do. For example: I have 10 rows in the listview, and in column serial no rows goes from 1-10. Suppose I remove rows 4,5,6 from the listview, the remaining rows left like this 1,2,3,7,8,9,10.

What I want is the numbers of rows reset automatically. Instead 1,2,3,7,8,9,10 I want the numbers to be automatically reset to 1,2,3,4,5,6,7 without effecting the other columns. Can you please try with my code ????
Bandi Ramesh 14-Feb-13 5:12am    
can you post your ListView1 code to better understand your problem

1 solution

C#
private void RemoveSelectedItem_Click(object sender, EventArgs e)
{
    if (TbSearchDCNo.Text != "")
    {
        Connection();
        ListViewItem item = listView1.SelectedItems[0];
        cmd = new SqlCommand("delete from DeliveryChallan where SNo='"+item.SubItems[0].Text+"'", cs);
        cmd.ExecuteNonQuery();
        listView1.Items.Remove(listView1.SelectedItems[0]);
        for (int i = 0; i <= listView1.Items.Count - 1; i++)
        {
            listView1.Items[i].Text = (i + 1).ToString();
        }
        GrandTotalCalc();
        listView1.Refresh();
        listView1.Update();
        BtnDcModify.Focus();
    }
    else
    {
        listView1.Items.Remove(listView1.SelectedItems[0]);
        for (int i = 0; i <= listView1.Items.Count - 1; i++)
        {
            listView1.Items[i].Text = (i + 1).ToString();
        }
        GrandTotalCalc();
        listView1.Refresh();
        ICBItemCode.Focus();
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900