Click here to Skip to main content
15,917,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I wrote following code for filter values in data gride

string wordsForSearch = cmbWords.SelectedItem.ToString();
            string index1 = cmbCountLowerLimit.SelectedItem.ToString();

            for (int i = 0; i < dgvFilter.RowCount; ++i)
            {

                string a = dgvFilter.Rows[i].Cells[wordsForSearch].Value.ToString().ToLower();

                while (i > 0 )
                {
                    dgvFilter.Rows.RemoveAt(i);
                }
   
            }


It gives Row index provided is out of range.
Parameter name: index
exception please help me if you can give sample code it will be very useful.
Posted
Updated 22-Aug-10 11:54am
v3
Comments
Dalek Dave 22-Aug-10 17:54pm    
Minor Edit for Grammar.

while (i < 0 )

Hey buddy, what do you think that means in the light of for loop? Is there any chance that code running ever?
 
Share this answer
 
Comments
Kasunmit 22-Aug-10 12:54pm    
sry sry it must be like this i>0 :D even though it like this its gives Row index provided is out of range.
Parameter name: index this excepetion
Did you try debugging?

Looks like, the for loop was initiated for let say 1 to 5 but inside loop you remove the rows and thus the acutal number of rows in dataview are less. Comment the remove part and check and then try to put the logic needed.
 
Share this answer
 
Comments
Kasunmit 22-Aug-10 15:33pm    
yhh thats correct
Kasunmit 22-Aug-10 15:34pm    
but when i am delete while loop it running giving output but giving answer by clicking the button (i runing that loop inside the button)more than one time y is that ?? pls help

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