如何在datagridview中添加默认行?

时间:2013-01-28 18:11:35

标签: c# datagridview datatable

我有datagridview绑定到由用户输入过滤的DataView(用户输入客户)。我甚至需要显示输入时没有购买的客户。所以基本上我需要添加一个显示customerId的默认行还有一些默认值,比如0,00。这是我到目前为止所做的但是徒劳无功。谢谢你的帮助。

string[] lines =new string[dataGridView1.Rows.Count-1]; 
int j= 0; 
for (int i = 0; i < dataGridView1.Rows.Count-1 ; i++)
{ 
   if ((string)dataGridView1.Rows[i].Cells[0].Value != "" && dataGridView1.Rows[i].Cells[0].Value !=null) 
   { 
       lines[j] = dataGridView1.Rows[i].Cells[0].Value != null ? dataGridView1.Rows[i].Cells[0].Value.ToString() : string.Empty; j++; 
   }
 } 

 DataView dv = new DataView();
dv.Table = this.dataSet1.PROMET_DOB_BEZM;
dv.RowFilter = string.Format("CustomerID IN ('{0}')", string.Join("','", lines));
DataTable tabel = new DataTable();
tabel = dv.ToTable();

foreach (string line in lines)
{
    for (int i = 0; i < tabel.Rows.Count - 1; i++)
    {
        if (!tabel.Rows[i]["CustomerID"].ToString().Contains(line))
        {
            DataRow dr = dv.Tabel.NewRow();
            tabel.Rows.Add(dr);
        }
    }
}

dataGridView2.DataSource = tabel; 

0 个答案:

没有答案