Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET
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 13-Feb-13 20:21pm
Comments
KalaiPondy at 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 at 14-Feb-13 5:12am
   
can you post your ListView1 code to better understand your problem

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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();
    }
}
  Permalink  

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

  Print Answers RSS
0 Maciej Los 230
1 OriginalGriff 202
2 Richard MacCutchan 185
3 Tomas Takac 146
4 CPallini 125
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 1 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100