datagridview中的数据清除错误 [英] data clearance error in datagridview
本文介绍了datagridview中的数据清除错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是代码部分
here is the code part
private void btnSearch_Click(object sender, EventArgs e)
{
//dgvSearch.Rows.Clear();
int name = Convert.ToInt32(cboxJewlName.SelectedValue);
int material=Convert.ToInt32(cboxJewlMaterial.SelectedValue) ;
DataTable table = Bllcombohelper.getAllSelectedJewl(name, material);
int roows=table.Rows.Count;
int j=0;
while (j < roows)
{
if (j > 14)
{
dgvSearch.Rows.Add(1);
dgvSearch.ScrollBars = ScrollBars.Vertical;
}
dgvSearch.Rows[j].Cells[0].Value = table.Rows[j].ItemArray[0].ToString();
dgvSearch.Rows[j].Cells[1].Value = table.Rows[j].ItemArray[5].ToString();
dgvSearch.Rows[j].Cells[2].Value = table.Rows[j].ItemArray[6].ToString();
dgvSearch.Rows[j].Cells[3].Value=table.Rows[j].ItemArray[7].ToString()+"/-";
dgvSearch.Rows[j].Cells[4].Value = table.Rows[j].ItemArray[4].ToString();
j = j + 1;
}
//table.Clear();
}
我用了dgvSearch.Rows.Clear();
在上面评论的位置,但没有成功
also i tried table.Clear();
在上面的位置评论中,但它也没有帮助.
我应该怎么做,以便在下次单击搜索按钮时,首先清除datagridview的旧值...然后处理,以显示具有某些不同属性的搜索项
感谢您的帮助
i used dgvSearch.Rows.Clear();
in the position commented above but it didn''t work
also i tried table.Clear();
in the postion comment above but it also didn;t helped.
what should i do so that on the next click of search button the old value of datagridview first get cleared...and then procced to display the search item with some diffrent attribute
thank u for ur help
推荐答案
尝试
table.Clear();
dgvSearch.DataSource = table;
private void btnSearch_Click(object sender, EventArgs e)
{
dgvSearch.DataSource = null;
dgvSearch.Rows.Clear();
dgvSearch.Columns.Clear();
// Your code
}
希望这会有所帮助!
Hope this helps!
这篇关于datagridview中的数据清除错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文