如何使用C#在Data GridView中添加序列号 [英] How to add Serial number in Data GridView using C#
本文介绍了如何使用C#在Data GridView中添加序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友
您能告诉我如何在运行时在Data Gridview中设置序列号意味着在运行时我插入多少行序列号也得到+1;
谢谢:
Dear Friends
Can you please tell me how to set serial Number in Data Gridview at run time means at runtime how many row i insert Serial number get also +1;
thanks:
推荐答案
/add a column for serial no
DataSet ds = new DataSet();
DataColumn c = new DataColumn();
c.ColumnName = "Serial No.";
c.DataType = typeof(int);
ds.Tables.Add("TableA"); //add a table
ds.Tables[0].Columns.Add(c); //add the column
ds.Tables[0].Columns[0].AutoIncrement = true; //set the autoincrement (it starts from 0)
//this two lines add a blank row for the serial no '0' and remove it
//that way the serial number starts from 1 , instead of 0 for the fetched records.
ds.Tables[0].Rows.Add(0);
ds.Tables[0].Rows[0].Delete();
//after this you can upload the fetched records in a regular way (please refer "TableA" and dataset ds though) (see this codeguru.com link: http://www.codeguru.com/forum/showthread.php?t=452168 " (How to display large number of rows in a DataGridView?)
请参阅以下链接....
http://stackoverflow.com/questions/8698443/how-to-show-serial-no-in-data-grid-view-in-c-sharp-windows-forms [ http://social.msdn.microsoft.com/Forums/ar/winforms/thread/0c903865-bece-4fc0-b43b-c113b10341dc [
Refer these links....
http://stackoverflow.com/questions/8698443/how-to-show-serial-no-in-data-grid-view-in-c-sharp-windows-forms[^]
http://social.msdn.microsoft.com/Forums/ar/winforms/thread/0c903865-bece-4fc0-b43b-c113b10341dc[^]
看看这个....
在gridview中生成序列号 [
Have a look at this....
Generate serial number in gridview [^]
这篇关于如何使用C#在Data GridView中添加序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文