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

Access Custom Object associated with Row

1 Answer 55 Views
GridView
This is a migrated thread and some comments may be shown as answers.
K.
Top achievements
Rank 1
K. asked on 03 Sep 2010, 10:00 PM
I'm evaluating your controls for use in my project and I have a question.

This is my case:
1. I use SQLite Db and I would like to display data from specific table in the Grid.
2.I wold like to access all attributes of the row(s) selected in the grid (when user invokes context menu).
    The context menu will depend on certain attributes of the Row. (some menu items will be enabled or disabled).


How can I accomplish this?

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 08 Sep 2010, 06:09 PM
Hello konrad krupa,

You can achieve the explained scenario easily with the RadGridView control. You can change the items of the context menu in the ContextMenuOpening event:

private void radGridView1_ContextMenuOpening(object sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e)
{
    // ContextMenuProvider can be GridCellElement instance. This is the cell for which the context menu is shown.
    GridCellElement cellElement = e.ContextMenuProvider as GridCellElement;
    if (cellElement != null)
    {
        e.ContextMenu.Items.Add(new RadMenuItem("MenuItem"));
    }
}

You can access the selected row through the SelectedRows collection:

GridViewDataRowInfo dataRow = this.radGridView1.SelectedRows[0] as GridViewDataRowInfo;

If you want to access the column value of specified row you should use its Cells collection:

int value = (int)dataRow.Cells["ID"].Value;

Regards,
Svett
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
K.
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or