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
Hi Curtis,
Can we have button Column in XamDataGrid or XamdataPresenter..?
Absolutely.
Here is a complete working example of having a column of Buttons. In the following example, notice how the Button is declared in a CellValuePresenterStyle and how the Button Content is bound to the data. You could also add a Click event handler or a Command to the Button to handle when the user clicks on the Button.
<igDP:XamDataGrid xmlns:igDP="http://infragistics.com/DataPresenter">
<igDP:XamDataGrid.Resources> <XmlDataProvider x:Key="BookData" XPath="/Books"> <x:XData> <Books x:Uid="Books_1" xmlns=""> <Book ISBN="0-7356-0562-9" Stock="in"> <Title>XML in Action</Title> <Summary>XML Web Technology</Summary> </Book> <Book ISBN="0-7356-1370-2" Stock="in"> <Title>Programming Microsoft Windows With C#</Title> <Summary>C# Programming</Summary> </Book> </Books> </x:XData> </XmlDataProvider>
<Style x:Key="FieldButton" TargetType="{x:Type igDP:CellValuePresenter}" > <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <Button Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" Margin="4,1,4,1" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"/> </ControlTemplate> </Setter.Value> </Setter> </Style> </igDP:XamDataGrid.Resources>
<igDP:XamDataGrid.DataSource> <Binding Source="{StaticResource BookData}" XPath="Book"/> </igDP:XamDataGrid.DataSource>
<igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoArrangeCells="LeftToRight" AutoGenerateFields="False" /> </igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout > <igDP:FieldLayout.Fields>
<igDP:Field x:Uid="ISBN" Name="ISBN"/>
<igDP:Field Name="Stock" Label="Stock" > <igDP:Field.Settings> <igDP:FieldSettings CellMinWidth="150" CellWidth="150" CellValuePresenterStyle="{StaticResource FieldButton}" /> </igDP:Field.Settings> </igDP:Field>
<igDP:Field x:Uid="Title" Name="Title"/>
<igDP:Field x:Uid="Summary" Name="Summary"/>
</igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts></igDP:XamDataGrid>
Instead of Button I am trying to use ComboBox. Also The datasource has Property OptionItems which is of collection type. I am trying to bind this OptionItem to the ComboBox in the Cell of the respective record.
I modified the Style as follows..
<Style x:Key="FieldButton" TargetType="{x:Type igDP:CellValuePresenter}" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<ComboBox ItemsSource="{Binding
RelativeSource={RelativeSource TemplatedParent},
Path=OptionItems}" Margin="4,1,4,1"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height
}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
It doesent give me items from
OptionItems
proeprty in to the ComboBox. Any Idea where I am making mistake.?
Hi Chetan,
So you need help getting the DataTrigger to work and the Button? DataTriggers with hard coded indeices are always tricky to debug. What would help me help you is if you were to create a sample project that illustrates the problem. Attach the project and I will debug the problem and then report back with the solution.
Also, please clarify if this issue is just related to the selected row data trigger or if you need help with the ComboBox/Button issue. Since that is a different issue, it mght be better to post a new post for that one. You can email me the post so I might look into it in case another Infragistics engineer doesn't answer it first.
Thanks!
I have a List with field as IsDefault and I assigned it as datasource to XAMDataPresenter. I want the record get selected when IsDefault field has value TRUE. (Only one record will have TRUE value)
I tried this...
<Style TargetType="{x:Type InfraXamGrid:DataRecordPresenter}"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},Path=DataRecord.DataItem.IsDefault}" Value="true"> <Setter Property="IsSelected" Value="True"/> <Setter Property="IsActive" Value="True"/> </DataTrigger> </Style.Triggers> </Style>
Please let me know if you need more information about the problem.
The comboBox issue is different than this problem.
Hi Custis,
As we discussed, sharing the solution of the problem mentioned above by me..
Problem inshort: When we bind any object(which is not a string) to DataGrid field, the field not remains sortable.
Solution: Create an UnBound Field and set Binding to it as follows.
<InfraGrid:UnboundField BindingPath="[ObjectName].[PropertyName]" Label="Preferred Description" Width="480">
In my case I had a Colloection as a datasource. The collection was of class which has a field of type RecordType. When I bind the colloection to a DataGrid, RecordType field gets assigned to one of the fields. As I override ToString method of RecordType class and returned RecordName, I could see the RecordNames in the field but cound not sort the field. When I used Unbound field and explicitely set the BindingPath to the RecordName, I cound see the RecordNames in the field as well as could sort the field.
Hello Chetan,
I received your sample. I will get back to you as soon as I determine what the problem is and will communicate the solution here for other users as well.
Thank you!
I tried following but not working.
EditAsType="{x:Type Sys:String}" on FieldSettings
can I try anything else to solve the issue?
Sent you an email with the sample application attached.
Please let me know if you need more details about the issue.
Chetan
You may need to explicitly set the type to string in the Field Settings. If you could replicate the issue in a smaller sample project, I could better determine why sorting isn't working and correct the problem.