1. 填入(通常從資料庫)Dataset的值後,先新增mySeq欄到此Dataset :
2. Datagridview指定DataSource和 DataMember :
3. Datagridview的RowPostPaint Event 新增以下 :
Read More »
if (!myDataset.Tables["myTable"].Columns.Contains("mySeq")) myDataset.Tables["myTable"].Columns.Add("mySeq", typeof(int));
2. Datagridview指定DataSource和 DataMember :
dataGridView1.DataSource = myDataset; dataGridView1.DataMember = "myTable";
3. Datagridview的RowPostPaint Event 新增以下 :
private voiddataGridView1_RowPostPaint(object sender,DataGridViewRowPostPaintEventArgs e) { if((dataGridView1.Rows[e.RowIndex].Cells["mySeq"].Value).ToString() == "") dataGridView1.Rows[e.RowIndex].Cells["mySeq"].Value = e.RowIndex + 1; else return; }