This is a migrated thread and some comments may be shown as answers.

GridViewSelectedRowsCollection.Add

4 Answers 96 Views
GridView
This is a migrated thread and some comments may be shown as answers.
HamiD Mayeli
Top achievements
Rank 1
HamiD Mayeli asked on 26 Oct 2009, 06:46 PM
Hi,

I`m Using GridViewSelectedRowsCollection but after adding Obj  into it, still it`s count == 0.

GridViewSelectedRowsCollection RowCollection = new GridViewSelectedRowsCollection();  
RowCollection.Add(RadGrid1.CurrentRow); 

Regards.

4 Answers, 1 is accepted

Sort by
0
Matthew O'Connor
Top achievements
Rank 1
answered on 27 Oct 2009, 12:47 PM
hey,

I am not exactly sure about that, but it seems reasonable that you add a row, not just an Object.

Matt
0
Nick
Telerik team
answered on 28 Oct 2009, 08:22 AM
Hi,

You can select any GridViewRowInfo by setting its IsSelected property to true, for instance:

this.radGridView1.CurrentRow.IsSelected = true;

Do not hesitate to write me back if you have further questions.

All the best,
Nick
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
HamiD Mayeli
Top achievements
Rank 1
answered on 28 Oct 2009, 03:46 PM
Hi Nike Tanx for your helps.

But i have a gird and user can select some row from this grid and delete rows with click on a button, and i wanna find a why it do it.
i cant use foreach or for statment cuz when i delete or remove a row selectedrows collection will change, so i will delete wrong rows.
and for {this.radGridView1.CurrentRow.IsSelected = true;} i think execute a loop on a grid with more than 1,000,000 rows for delete 5 or 6 rows not rational.

Best Regards.
0
Nick
Telerik team
answered on 02 Nov 2009, 12:00 PM
Hello HamiD Mayeli,

Thank you for contacting us. Your question is really related to .net framework, but not RadGridView. Anyway, I can suggest that you copy the SelectedRows collection in another collection used just for this purpose, and then use the new collection to delete the rows.

private void radButton3_Click(object sender, EventArgs e)
        {
            List<GridViewDataRowInfo> l = new List<GridViewDataRowInfo>();
            foreach (GridViewDataRowInfo info in this.radGridView1.SelectedRows)
            {
                l.Add(info);
            }
 
            foreach (GridViewDataRowInfo row in l)
            {
                this.radGridView1.Rows.Remove(row);
            }
        }

There are many forum posts on the internet answering this question.

Sincerely yours,
Nick
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
HamiD Mayeli
Top achievements
Rank 1
Answers by
Matthew O'Connor
Top achievements
Rank 1
Nick
Telerik team
HamiD Mayeli
Top achievements
Rank 1
Share this question
or