Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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();
  }

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
Posted
Updated 15-Aug-11 21:43pm
v2

Try
table.Clear();
dgvSearch.DataSource = table;
 
Share this answer
 
Comments
amsainju 16-Aug-11 2:37am    
it didn't worked :(
C#
private void btnSearch_Click(object sender, EventArgs e)
{
 dgvSearch.DataSource = null;
 dgvSearch.Rows.Clear();
 dgvSearch.Columns.Clear();

// Your code
}


Hope this helps!
 
Share this answer
 
v2
Comments
amsainju 16-Aug-11 2:33am    
there is no such property such as datbind in c#...
senthil sennu 16-Aug-11 2:35am    
Sorry, I thought u want to clear gridview. If it is a windows application u can use dgvSearch.DataSource = null; alone.
Ashika s 16-Aug-11 2:37am    
this is not working in windows application.:(
amsainju 16-Aug-11 2:40am    
ya not working in windows application :(
senthil sennu 16-Aug-11 2:50am    
dgvSearch.DataSource = null;
dgvSearch.Rows.Clear();
dgvSearch.Columns.Clear();

I am using the above three line to clear my grid. Its working fine here. pls chk

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900