本文介绍了关于在列表视图中删除行时的行号的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我已经在数据库中添加了行号

但是删除行时出现问题

Now i''ve add row number in database already

but i''ve problem when i''ve delete row

private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
       {
           for (int i = 0; i <= listView1.SelectedItems.Count - 1; i++)
           {
               ListViewItem lvi = listView1.SelectedItems[i];
               listView1.Items.Remove(lvi);
           }
       }



示例我删除了第3行,我删除了5行

第一行编号为12345
当我删除它时会显示1245
我希望它成为1234

我找到了解决此问题的方法,但是它在VB中

在此链接上 http://www.pcreview.co.uk/forums/row-number -listview-t1417082.html [ ^ ]

我已经尝试了很长时间,但是还没有解决办法

请任何人帮助我

非常感谢您



Example i''ve delete row number 3 and i''ve 5 row

first row number is 12345
When i''ve delete it''s show 1245
i want it gonna be 1234

i find solution for this Problem but it''s in VB

on this link http://www.pcreview.co.uk/forums/row-number-listview-t1417082.html[^]

I''ve try for long time but i haven''t got a solution

Please anyone to Help me

Thankyou so much

推荐答案



private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
       {
           DataTable dt1 = new DataTable();//<< datatable เปล่า
           string[] data_new = new string[7];//<< ตาม column
           int countnum = 0;
           dt1.Columns.Add("No.", typeof(string));
           dt1.Columns.Add("ID", typeof(string));
           dt1.Columns.Add("NAME", typeof(string));
           dt1.Columns.Add("Price", typeof(string));
           dt1.Columns.Add("Quantity", typeof(string));
           dt1.Columns.Add("Summary", typeof(string));
           dt1.Columns.Add("Lot.", typeof(string));

           for (int i = 0; i < listView1.Items.Count; i++)
           {
               if (listView1.Items[i].Selected == false) //<< inverse Select
               {
                   countnum += 1;
                   data_new[0] = (countnum).ToString();
                   data_new[1] = listView1.Items[i].SubItems[1].Text;
                   data_new[2] = listView1.Items[i].SubItems[2].Text;
                   data_new[3] = listView1.Items[i].SubItems[3].Text;
                   data_new[4] = listView1.Items[i].SubItems[4].Text;
                   data_new[5] = listView1.Items[i].SubItems[5].Text;
                   data_new[6] = listView1.Items[i].SubItems[6].Text;

                   dt1.Rows.Add(data_new); //datatabel ใหม่ที่ลบแล้ว
               }
           }
           int fc = dt1.Columns.Count;
           listView1.Items.Clear();
           foreach (DataRow row in dt1.Rows)
           {
               string[] subitems = new string[fc];
               object[] o = row.ItemArray;
               for (int i = 0; i < fc; i++)
               {
                   subitems[i] = o[i].ToString();
               }
               ListViewItem item = new ListViewItem(subitems);
               listView1.Items.Add(item);
           }
           for (int i = 1; i <= listView1.SelectedItems.Count ; i++)
           {
               ListViewItem lvi = listView1.SelectedItems[i];
               listView1.Items.Remove(lvi);
           }
           CalculateNet();
       }


这篇关于关于在列表视图中删除行时的行号的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 05:49