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

i have a grid view ,this grid view contains check box at each row ,when i am checking the check box then related row is being bind into another grid,i want that if selected record is already existing into the second grid then the those row should not be added into the second grid.
in concise way i want to prevent the selection of already existing record .

waiting for your view ,provide me code if possible.


thanks
Posted

in concise way i want to prevent the selection of already existing record .
Before adding first grid selected datarow as one of the rows of datatable to be bind with grid2 (probably it would be check box clicked event), you need to loop through new datatable and see if record already exists - If so, skip adding.

Thus, there would be a foreach loop on second grid datasource table. loop and match the unique rowid that already exists with the rowid of current selected item. If you find a match break the loop and return. If you dont find a match after whole foreach loop comes to an end, add the new record to table. Try!

If you were doing this in ASP.NET, you could have kept a copy of selected record id's on client side and handled the checkbox in Javascript.
 
Share this answer
 
Comments
Espen Harlinn 26-May-12 4:38am    
Good points :-D
Monjurul Habib 26-May-12 15:48pm    
5!
C#
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int index = e.RowIndex;

            if ((bool)dataGridView2.Rows[index].Cells[0].Value == true)
            {
                //The data is true
                //Cells[0] is the checkbox control
                //dataGridView2.Rows[index].Cells[0].Value returns an object so you must cast it to a boll using (bool)
            }
        }
 
Share this answer
 

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