Hi,
I have XamDataPresenter, we are binding this XamDataPresenter with XML file and data is displaying in Tabular form, My problem is that while right click on any Row( Record), i didn't get Row(Record value), Actually my requirement is that when rigth click on any row i want row index, so i can get any column value on that bases of that index value.
Thanks,
Ajay
Hello Ajay,
Usually a right-click will invoke a contextual menu when implemented. Do your requirements specify a contextual menu of a list of indices appearing? If not, please clarify what you would like to accomplish.
Curtis
Hello Curtis,
We want to select context menu at run time depending upon type of the record on which the Mouse rightClick event occured . i.e. if there are two levels of records in the Datapresenter e.g. First row contains Order and rows following to it contains Products in the Order.
I have 2 Context Menus, one for Orders and second for Products.
Suppose when I right click on Order Record (Row) then I need to show the context menu for Orders and when I Right Click on any of the Product record which belongs to any of the Order record then I need to show context menu for Products.
The problem which we are facing is that before right clicking on any record, we are supposed to first left click on it , make it as Activerecord and the we need to right click on it so that we can identify the records (whether it is order record or product record ) at runtime and decide which context menu we should show Up.
Here is some code for Right Click event
private void DataPresenter_MouseRightButtonDown(object sender, MouseButtonEventArgs e) {
DataRecord drCurrent = (DataRecord)DataPresenter.ActiveRecord;
if(drCurrent.Cells[0].Value =="Product")
DataPresenter.ContextMenu = ProductContextMenu;
else
DataPresenter.ContextMenu = OrderContextMenu;
}
The expected behaviour is that when we RightClick on any record of Datapresenter, the record should become Activerecord of the Datapresenter (instead of first left click on the record, make it activeRedord and then Right click on the same record).
Please let us know whether we are missing any event of Datapresenter which provides expected functionality.
Chetan Deshmukh
Helo Chetan,
Right-clicking does not automatically select cells or rows in the xamDataGrid. There is a way to get what you want though.
The xamDataGrid contains the ContextMenuOpening event which gets called when the user right clicks on the grid. In the code behind method for this event, you can use WPF methods to determnine the underlying cell from the mouse coordinates of the click. After determining the cell, you can select the cell and build and display a contextual menu dynamically by assigning it to the grid. This way the contextual menu will open immediately after. You will need to respond to events in the context menu to determine which menu was selected.
To determine the cell beneath the right click, you would need to write some code using the VisualTreeHelper.HitTest static method.
Here is a forum post I found that gives a small example of using HitTest: http://www.developersdex.com/asp/message.asp?p=2912&ID=%3COuzVF49UIHA.3364%40TK2MSFTNGP03.phx.gbl%3E
The xamDataGrid does not provide this functionality for you. You are welcome to request this functionality as a new feature at:
If you need further assistance with this, please let me know and I will be happy to help!
Thanks Curtis
One question : Is the above solution applicable for both xamDataGrid and XamDataPresenter...?
Done
Here is some code i would like to share with You....
void AssetGrid_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) { // VisualTreeHelper.HitTest(dw.ucAssetGrid.AssetGrid, null, HitTestResultFunc, new // PointHitTestParameters(e.GetPosition(dw.ucAssetGrid.AssetGrid))); RightClickReturn = true; VisualTreeHelper.HitTest(dw.ucAssetGrid.AssetGrid, HitTestFilterFunc, HitTestResultFunc, new PointHitTestParameters(e.GetPosition((UIElement)sender)));
public HitTestResultBehavior HitTestResultFunc(HitTestResult result) { DependencyObject dobj = result.VisualHit; // lbxResult.Items.Add(dobj.GetType().Name); //MessageBox.Show(VisualTreeHelper.GetParent(dobj).GetType().ToString());
if (RightClickReturn ==true && VisualTreeHelper.GetParent(dobj).GetType().ToString() =="Infragistics.Windows.DataPresenter.DataRecordPresenter") { DataRecordPresenter rp = (DataRecordPresenter)VisualTreeHelper.GetParent(dobj); dw.ucAssetGrid.AssetGrid.SelectedItems.Records.Clear(); rp.Record.IsSelected = true; rp.Record.IsActive = true; RightClickReturn = false; // return ; } return HitTestResultBehavior.Continue; }
public HitTestFilterBehavior HitTestFilterFunc(DependencyObject potentialHitTestTarget) { //lbxResult.Items.Add(potentialHitTestTarget.GetType().Name); return HitTestFilterBehavior.Continue; }
The above code is working as per expected.
chetan.deshmukh@e-zest.in