So I know how to return any value using the CurrentRow. Let's say a user has one row selected, and they right-click on a different row, I need to retrieve the value from that row. I've been looking at CurrentRowChanging & Changed as I suspect I need to capture the value there. I think my issue is the value being returned now is the value from the previously selected row and I'm not aware of the event trigger hierarchy.
Any help? Thanks
4 Answers, 1 is accepted
Thank you for writing.
You can use the MouseClick or the CellClick event:
void
radGridView1_MouseClick(
object
sender, MouseEventArgs e)
{
GridDataCellElement element = radGridView1.ElementTree.GetElementAtPoint(e.Location)
as
GridDataCellElement;
if
(element !=
null
)
{
string
value = element.Value.ToString();
}
}
void
radGridView1_CellClick(
object
sender, GridViewCellEventArgs e)
{
string
value = e.Value.ToString();
}
Let me know if you have additional questions.
Regards,
Dimitar
Telerik
I haven't had any luck with this and I may have failed in explaining myself better.
We have a custom context menu, and when that context menu is rendered it is supposed to pick up a value from a particular column on the selected row. As it is right now, it is picking up the value previously selected when the user right clicks on a different row. I need to pick up the new value from a column on the new row, the row the user right-clicked on.
It works if the user first left-clicks to select the row, then right-clicks. But if all they do is right click on another arbitrary row, it's picking up the previous value.
Thanks
Update: I've tried capturing the value I need in the CurrentRowChanged (past tense right?), but in debug mode I can visually see the event fire before the new row is in fact changed.
Is the only reliable means to left click one, then right click?
Thank you for writing back.
In this case, it would be better to use the ContextMenuOpening event to retrieve the cell value. The following snippet shows how you can get the value in the item Click event handler:
private
RadContextMenu contextMenu;
object
cellValue =
null
;
private
void
RadForm1_Load(
object
sender, EventArgs e)
{
contextMenu =
new
RadContextMenu();
RadMenuItem menuItem1 =
new
RadMenuItem(
"Item 1"
);
menuItem1.Click += menuItem1_Click;
contextMenu.Items.Add(menuItem1);
}
void
radGridView1_ContextMenuOpening(
object
sender, ContextMenuOpeningEventArgs e)
{
e.ContextMenu = contextMenu.DropDown;
if
(e.ContextMenuProvider
is
GridDataCellElement)
{
cellValue = ((GridDataCellElement)e.ContextMenuProvider).Value;
}
}
void
menuItem1_Click(
object
sender, EventArgs e)
{
Console.WriteLine(cellValue.ToString());
}
I hope this helps.
Regards,
Dimitar
Telerik