Hi There,
I have a XamDataGrid binding to an observable collection of objects. I have a MouseLeftButtonUp. I want different actions based on column click by user. How can get a column name and datarecord in event handler.
================================================================
<igDP:XamDataGrid Grid.Row="0" x:Name="dataGrid" GroupByAreaLocation="None" MouseLeftButtonUp="DataGridMouseLeftButtonUp"> <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings AllowCellVirtualization="True" AllowEdit="False" CellClickAction="SelectRecord" SummaryDisplayArea="None" LabelClickAction="Nothing" /> </igDP:XamDataGrid.FieldSettings> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AllowDelete="False" AutoGenerateFields="False" AutoFitMode="Always" SelectionTypeRecord="None" RecordSelectorLocation="None" /> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="Col1" Label="Col1"/> <igDP:Field Name="Col2" Label="Col2"/> <igDP:Field Name="Col3" Label="Col3"/> <igDP:Field Name="Col4" Label="Col4"/> <igDP:Field Name="Col5" Label="Col5"/> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts></igDP:XamDataGrid>
private void DataGridMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e){ // Want to know which column and which record or cell value was clicked
}
Please let me know.
Thanking you in advance for help.
Nasir
Hello Nasir,
I can say that you don't need such cast since XamDataGrid's BringDataItemIntoView method takes an object and a boolean values. The first parameter is the object from your underlying data. Here you can read more about this method:
http://help.infragistics.com/Help/NetAdvantage/WPF/2013.1/CLR4.0/html/InfragisticsWPF4.DataPresenter.v13.1~Infragistics.Windows.DataPresenter.DataPresenterBase~BringDataItemIntoView.html
Hope this helps you
Hello Stefan,
I will use the site to add the request.
I have one last question.
Is there a way to cast underlying object (GridRow) to DataRecord. BringDataItemIntoView needs DataRecord and I have centerRecord which is type of GridRow.
================================================private ObservableCollection<GridRow> _gridRows;GridRow centerGridRow = _gridRows[center];DataRecord centerDataRecord = (DataRecord)centerGridRow ?????????????????datagrid.BringDataItemIntoView(centerDataRecord);================================================
I tried it, but couldn't cast it.
Please advise.
Thanks
You can use the XamDataGrid’s BringDataItemIntoView method in order to scroll to a particular DataItem, but it is not centered. You can either implement this functionality by scrolling the grid manually or you can suggest new product ideas for future versions (or vote for existing ones) at <http://ideas.infragistics.com>.
There are many benefits to submitting an product idea:
- Direct communication with our product management team regarding your product idea.
- Notifications whenever new information regarding your idea becomes available.
- Ability to vote on your favorite product ideas to let us know which ones are the most important to you. You will have ten votes for this and can change which ideas you are voting for at any time.
- Allow you to shape the future of our products by requesting new controls and products altogether.
- You and other developers can discuss existing product ideas with members of our Product Management team.
Steps to create your idea:
1. Log into the Infragistics Product Idea site at http://ideas.infragistics.com (creating a new login if needed).
2. Navigate to the product / platform channel of your choice (e.g. WPF, Windows Forms, ASP.NET, HTML5 / Ignite UI, iOS / NucliOS, etc.)
3. Add your product idea and be sure to be specific and provide as much detail as possible. Explain the context in which a feature would be used, why it is needed, why it can’t be accomplished today, and who would benefit from it. You can even add screenshots to build a stronger case. Remember that for your suggestion to be successful, you need other members of the community to vote for it. Be convincing!
The Product Idea site puts you in the driver’s seat and allows you to track the progress of your ideas at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you.
Thanks for the reply. It looks good now.
I have another question related to same grid. I want to center the grid to a particular record without using scroll bar. Grid has more than 500 rows and I want to center it to a particular record so that it can display that record exactly on the center, regarding the height of the xamDataGrid.private
================================================private ObservableCollection<GridRow> _gridRows;GridRow centerRecord = _gridRows[center];================================================
How can I scroll the grid automatically so that it displays centerRecord exactly in the center. This centerRecord keeps changing and I want to make sure on every update of centerRecord, grid gets re-centered automatically. Let me know if you have sample code for this.
Thanking you in advance for your help.
You can add the following if statement in order to check if the user clicks over the Thumb or the RepeatButton:
if (!(e.OriginalSource is RepeatButton) && !(e.OriginalSource is Thumb)) { string fieldName = (sender as XamDataGrid).ActiveCell.Field.Name; GridRow r = ((sender as XamDataGrid).ActiveRecord as DataRecord).DataItem as GridRow; }
Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.