Hello,
I created a xamDataGrid with 1 column. Each cell has my custom control - a modified ComboBox. The DataSource is set to a BindingList. I have set AllowAddNew="True" and AllowEdit="True" AddNewRecordLocation="OnBottom"
The grid shows up with one row, with one column, and I can interact with my custom control.
Once I finish setting up values in my control - when the data record corresponding to row has a valid value, I would like to add a new empty row at the bottom of the grid. How can this be done? Currently I can set the value on the row but no new row shows up. Is there something my control needs to implement to notify the grid that the current row is set?
Please help!
I am sorry, I was not able to understand what the problem was. Can you attach a sample project that reproduces this issue?
Hi Alex,
I looked some more at the problem I have and here is what I see. I have a grid where I set each cell presenter to my custom control (that control extends UserControl). I bind my grid's DataSource to a BindingList. When I set the some value on my custom control in the grid, the value is not being reflected in the underlying BindingList. I suspect that my custom control is not implementing some methods/events that are required for the value from the control to be commited and reflected in the DataSource...
Marcin
Marcin,
The issue here is that you have to bind the element in the custom control that holds your value to the cell's value.
Please take a look at this blog post by Andrew Smith on hosting elements in the CellValuePresenter, which you might find helpful:
http://blogs.infragistics.com/blogs/andrew_smith/archive/2009/03/27/hosting-wpf-controls-in-a-xamdatagrid-cell.aspx
Thank you for your reply.
I have a follow up question. I have created a ControlTemplate that basically tries to use my control in a cell. I am able to bind the grid to BindingList<Account> where Account has a property called Name.
Here is the code for ControlTemplate and the Grid.
<infragisticsDataPresenter:XamDataGrid Name="popUpDataGrid"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Grid.Row="1">
<infragisticsDataPresenter:XamDataGrid.Resources>
<Style x:Key="FavoritesLookupControlStyle"
TargetType="{x:Type infragisticsDataPresenter:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type infragisticsDataPresenter:CellValuePresenter}">
<tdsFavorites:TdsFavoritesLookupControl x:Name="flcFirmAccount"
DataContext="{Binding Path=DataItem}"
SelectedItem="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Mode=TwoWay}"
DisplayMemberPath="{Binding ElementName=multiSelectComboBoxControl, Path=DisplayMemberPath, Mode=OneWay}"
ValuePath="{Binding ElementName=multiSelectComboBoxControl, Path=ValuePath, Mode=OneWay}"
TdsAdminService="{Binding ElementName=multiSelectComboBoxControl, Path=TdsAdminService, Mode=OneWay}"
FavoritesKey="{Binding ElementName=multiSelectComboBoxControl, Path=FavoritesKey, Mode=OneWay}"
CollectionLookup="{Binding ElementName=multiSelectComboBoxControl, Path=CollectionLookup, Mode=OneWay}"
ObjectType="{x:Type Reference:FirmAccount}"
ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=DisplayText, Mode=OneWay}"
Grid.Row="0"
Grid.Column="1" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</infragisticsDataPresenter:XamDataGrid.Resources>
<infragisticsDataPresenter:XamDataGrid.FieldSettings>
<infragisticsDataPresenter:FieldSettings AllowEdit="True" />
</infragisticsDataPresenter:XamDataGrid.FieldSettings>
<infragisticsDataPresenter:XamDataGrid.FieldLayoutSettings>
<infragisticsDataPresenter:FieldLayoutSettings AllowAddNew="True"
AddNewRecordLocation="OnBottom"
AutoGenerateFields="False"
AllowDelete="True"
SelectionTypeCell="Single" />
</infragisticsDataPresenter:XamDataGrid.FieldLayoutSettings>
<infragisticsDataPresenter:XamDataGrid.FieldLayouts>
<infragisticsDataPresenter:FieldLayout>
<infragisticsDataPresenter:FieldLayout.Fields>
<infragisticsDataPresenter:Field Name="Name"
Label="Account"
>
<infragisticsDataPresenter:Field.Settings>
<infragisticsDataPresenter:FieldSettings
CellValuePresenterStyle="{StaticResource FavoritesLookupControlStyle}"
LabelWidth="200"/>
</infragisticsDataPresenter:Field.Settings>
</infragisticsDataPresenter:Field>
</infragisticsDataPresenter:FieldLayout.Fields>
</infragisticsDataPresenter:FieldLayout>
</infragisticsDataPresenter:XamDataGrid.FieldLayouts>
</infragisticsDataPresenter:XamDataGrid>
The problem I have is that when I set the Field Name="Name", at run time I see that DataItem is set to corresponding Account from BindingList<Account>. However the SelectedItem is set to Account.Name. What I really want to do is to set the SelectedItem to the Account object.
I believe this is due to the fact that when I construct my grid I give it a field bound to "Name". Is there any way to bind the column to the underlying BindingList object, instead of object's property?
I was thinking about wrapping my Account object into another object that exposes Account property which would return Account and using that as Field Name. Another though is to use some DataConverter to convert from my string into the account object. But both of these solutions seem a bit complex. Is there any way to get the underlying object from BindingList into the SelectedItem property?
Any help would be very much appreciated.
Thank you,Marcin