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 Project I'm Using ListView With Columns(S.no, ItemCode, ItemName, color, Size, unit, Quantity, M.R.P, Total) and Created the S.no Columns as Auto Generate .While Inserting It Generates S.no automatically but while removing an item at the media the S.no not Updated.
 
For Example :
 

1 PB001 PANT Blue Small nos 10 150 1500
2 PB002 COTTONPANT Red Large nos 20 100 2000
3 PB003 JEANS Green Medium nos 30 100 3000
 
While Deleting (2nd) S.no, it showed Update (3rd) S.no to (2nd) S.no . But i stay as 3rd S.no in my listView.
 
My Coding :
 
public void LoadSNo()
{
Double Slno = 0;
if (listView1.Items.Count > 0)
{
 
foreach (ListViewItem Itm in listView1.Items)
{
if (Itm.SubItems[0].Text != "")
{
Slno = Convert.ToDouble(Itm.SubItems[0].Text);
}
else
{
Slno = 0;
}
Slno = Slno + 1;
}
 

ListViewItem Itm1;
if (TeSno.Text != "")
{
Itm1 = new ListViewItem(TeSno.Text);
}
else
{
Itm1 = new ListViewItem(Slno.ToString());
}
Itm1.SubItems.Add(ICBItemCode.Text);
Itm1.SubItems.Add(ICBItemName.Text);
Itm1.SubItems.Add(ICBColor.Text);
Itm1.SubItems.Add(TeSize.Text);
Itm1.SubItems.Add(CBEUnit.Text);
Itm1.SubItems.Add(TEQuantity.Text);
Itm1.SubItems.Add(TEMRP.Text);
Itm1.SubItems.Add(TETotal.Text);
Itm1.SubItems.Add(TeDummyID.Text);
listView1.Items.Add(Itm1);
TeDummyID.Text = "";
GrandCalc();
SalesClear();
return;
}

else
{
ListViewItem Itm2 = new ListViewItem("1");
Itm2.SubItems.Add(ICBItemCode.Text);
Itm2.SubItems.Add(ICBItemName.Text);
Itm2.SubItems.Add(ICBColor.Text);
Itm2.SubItems.Add(TeSize.Text);
Itm2.SubItems.Add(CBEUnit.Text);
Itm2.SubItems.Add(TEQuantity.Text);
Itm2.SubItems.Add(TEMRP.Text);
Itm2.SubItems.Add(TETotal.Text);
Itm2.SubItems.Add(TeDummyID.Text);
listView1.Items.Add(Itm2);
TeDummyID.Text = "";
GrandCalc();
SalesClear();
}
TeSno.Text = string.Empty;
}
Posted 13-Feb-13 20:07pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

if your serial number is row number of list view
then use tag in dataitem as
 
<%# Container.DataItemIndex + 1% >
 
then will provide row number 1,2,3 so on ...
 
and updated according after delete or remain maintained after sorting
  Permalink  
Comments
KalaiPondy at 26-Feb-13 4:11am
   
listView is created in WinForm using C# 2010 .
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  public void LoadSNo()
        {
            if (CheckListViewItems() == true)
            {
                Double Slno = 0;
                if (listView1.Items.Count > 0)
                {
 
                    foreach (ListViewItem Itm in listView1.Items)
                    {
                        if (Itm.SubItems[0].Text != "")
                        {
                            Slno = Convert.ToDouble(Itm.SubItems[0].Text);
                        }
                        else
                        {
                            Slno = 0;
                        }
                        Slno = Slno + 1;
                    }
 
                    ListViewItem Itm1;
                    if (TeSno.Text != "")
                    {
                        Itm1 = new ListViewItem(TeSno.Text);
                    }
                    else
                    {
                        Itm1 = new ListViewItem(Slno.ToString());
                    }
                    Itm1.SubItems.Add(ICBItemCode.Text);
                    Itm1.SubItems.Add(ICBItemName.Text);
                    Itm1.SubItems.Add(ICBColor.Text);
                    Itm1.SubItems.Add(TeSize.Text);
                    Itm1.SubItems.Add(CBEUnit.Text);
                    Itm1.SubItems.Add(TEQuantity.Text);
                    Itm1.SubItems.Add(TEMRP.Text);
                    Itm1.SubItems.Add(TETotal.Text);
                    Itm1.SubItems.Add(TeDummyID.Text);
                    Itm1.SubItems.Add(TeCategories.Text);
                    listView1.Items.Add(Itm1);
                    TeDummyID.Text = "";
                    GrandCalc();
                    SalesClear();
                    return;
                }
 
                else
                {
                    ListViewItem Itm2 = new ListViewItem("1");
                    Itm2.SubItems.Add(ICBItemCode.Text);
                    Itm2.SubItems.Add(ICBItemName.Text);
                    Itm2.SubItems.Add(ICBColor.Text);
                    Itm2.SubItems.Add(TeSize.Text);
                    Itm2.SubItems.Add(CBEUnit.Text);
                    Itm2.SubItems.Add(TEQuantity.Text);
                    Itm2.SubItems.Add(TEMRP.Text);
                    Itm2.SubItems.Add(TETotal.Text);
                    Itm2.SubItems.Add(TeDummyID.Text);
                    Itm2.SubItems.Add(TeCategories.Text);
                    listView1.Items.Add(Itm2);
                    TeDummyID.Text = "";
                    GrandCalc();
                    SalesClear();
                }
                TeSno.Text = string.Empty;
                listView1.Sort();
                listView1.Refresh();
                listView1.Update();
            }
            else
            {
                MessageBox.Show("Item Already Exit", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                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 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web03 | 2.8.141220.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