Hi.
I have found an issue in RadGridView when using multiselect and menu.
What i want to do is: select multiple lines, right click on RadGridView and execute some action on each line.
Apparently no big deal, done it with this code:
I only drag and drop a RadGridView control to my form, changed MultiSelect property to true and added a column.
Now, when i select multi lines (or just one line) i right click and the menu show up with my menu (and others... but also no big deal). If i chose my menu, the row value change from false to true and from true for false. Simple.
The real problem is when i order the column. After that, if i select more than one row and i select my menu, it is thrown this exception:
"InvalidOperationException: Collection was modified; enumeration operation may not execute."
According my visual studio the error it is in the foreach iteration, more exactly in the "in":
Ok... its a foreach problem. I try replace the foreach with a for statement:
With this solution, after i select both rows and right click and select my menu, i found out that
Think this is one bug in RadGridView (or i am doing someting really wrong...).
I would like some help/answer.
Kind Regards,
Bruno Almeida
I have found an issue in RadGridView when using multiselect and menu.
What i want to do is: select multiple lines, right click on RadGridView and execute some action on each line.
Apparently no big deal, done it with this code:
namespace
WindowsFormsApplication3
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
RadMenuItem mnuAdd =
new
RadMenuItem(
"Add"
);
private
void
radGridView1_ContextMenuOpening(
object
sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e)
{
e.ContextMenu.Items.Add(mnuAdd);
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
mnuAdd.Click +=
new
EventHandler(mnuAdd_Click);
radGridView1.Rows.AddNew().Tag =
false
;
radGridView1.Rows.AddNew().Tag =
false
;
}
void
mnuAdd_Click(
object
sender, EventArgs e)
{
foreach
(GridViewRowInfo row
in
radGridView1.SelectedRows)
{
row.Tag = !((
bool
)row.Tag);
row.Cells[0].Value = row.Tag;
}
}
}
}
I only drag and drop a RadGridView control to my form, changed MultiSelect property to true and added a column.
Now, when i select multi lines (or just one line) i right click and the menu show up with my menu (and others... but also no big deal). If i chose my menu, the row value change from false to true and from true for false. Simple.
The real problem is when i order the column. After that, if i select more than one row and i select my menu, it is thrown this exception:
"InvalidOperationException: Collection was modified; enumeration operation may not execute."
According my visual studio the error it is in the foreach iteration, more exactly in the "in":
foreach
(GridViewRowInfo row
in
radGridView1.SelectedRows)
Ok... its a foreach problem. I try replace the foreach with a for statement:
for
(
int
a = 0; a < radGridView1.SelectedRows.Count; a++)
{
radGridView1.SelectedRows[a].Tag = !((
bool
)radGridView1.SelectedRows[a].Tag);
radGridView1.SelectedRows[a].Cells[0].Value = radGridView1.SelectedRows[a].Tag;
}
With this solution, after i select both rows and right click and select my menu, i found out that
radGridView1.SelectedRows
only have one row, the one where i right click and is the only one that got changed.Think this is one bug in RadGridView (or i am doing someting really wrong...).
I would like some help/answer.
Kind Regards,
Bruno Almeida