Hey Guys,
I have a couple of editable cells in my XamDataGrid (Infragistics 14, .Net 4.0, Windows 7) and I'd like to display the initial values of these cells in tooltips - displayed when you hover over any of the editable cells. I tried doing this by adding a style like the following:
<Style x:Key="CellStyles" TargetType="{x:Type ig:CellValuePresenter}" BasedOn="{StaticResource {x:Type ig:CellValuePresenter}}" > <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEditingAllowed}" Value="True"> <Setter Property="ToolTip"> <Setter.Value> <Label Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ig:CellValuePresenter}, Path=ValueHistory.Count}" ContentStringFormat="Original Value: {0}"/></Setter.Value></Setter> </DataTrigger></Style.Triggers> </Style>
This was more of a test to see if I can show the ValueHistory.Count in the tooltip next to some text but it looks like my binding's messed up; I receive the following error:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Infragistics.Windows.DataPresenter.CellValuePresenter', AncestorLevel='1''. BindingExpression:Path=ValueHistory.Count; DataItem=null; target element is 'Label' (Name=''); target property is 'Content' (type 'Object')
Any suggestions on the above?
In regards to my actual usecase, I'm having trouble accessing the initial value from the ValueHistory. I set the three properties below as follows:
But I can't access the original value from the ValueHistory list in my xaml. Any ideas? Is there a better way to go about doing this? I considered binding a property to the tool tip value but I need the style to work for any editable cell on any grid that uses this style. Thanks in advance for your help!
I tried changing the setter to the following:
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Mode=Self}, Path=ValueHistory[ValueHistory.Count-1].Value}"/>
I used "ValueHistory[ValueHistory.Count-1].Value" because I noticed while debugging that the edits are appended to the list. I get the following errorwith this approach:
System.Windows.Data Error: 40 : BindingExpression path error: '[]' property not found on 'object' ''DataValueInfoHistory' (HashCode=6762647)'. BindingExpression:Path=ValueHistory[ValueHistory.Count-1].Value; DataItem='CellValuePresenter' (Name=''); target element is 'CellValuePresenter' (Name=''); target property is 'ToolTip' (type 'Object')
If possible, I would also like the formatting that I described above for my tool tip - "Old Value: xyz"
I got this to work using the following style:
<Setter Property="ToolTip"> <Setter.Value> <MultiBinding Converter="{StaticResource CellValueHistoryConverter}" StringFormat="Old Value: {0}"> <Binding RelativeSource="{RelativeSource Mode=Self}" Path="Field"/> <Binding RelativeSource="{RelativeSource Mode=Self}" Path="Record"/> </MultiBinding> </Setter.Value> </Setter>
And the following converter:
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values == null || values.Length != 2) return null;
var field = values[0] as Field; var record = values[1] as DataRecord; if (record == null || field == null) return null; var dataHistory = record.GetDataValueHistory(field); var lastItem = (dataHistory == null) ? null : dataHistory.Last(); return lastItem == null ? null : lastItem.Value; }
Is this the suggested way to do this or do I have other options? By the way, my string format is still not showing up - I had to add it to my converter
Hello Javier,
Thank you for your post.
I have been looking into it. I am glad that you have managed to resolve your first issue. About your requirement for StringFormat, what I can suggest is to add the string that you want to display before cell`s value directly in your converter. I created a short sample application based on your scenario to show you how you can implement this. If you are not able to reproduce the issue with the attached sample application, would you please modify it with the functionality, that you are using, so it reproduces the issue. This way I would be able to further investigate this for you and provide you with more detailed information on this matter. Please let me know if I am missing something about your scenario.
Please let me know if you need any further assistance on the matter.
Hey Nikolov,
Thank you for your response. It seems your demo is very similar to my approach - I was able to resolve both my issues with the code I posted last night. I was wondering if there's a better way to go about getting the initial value of a cell?
Is there a better way to go around getting the initial value of a cell?
Hello Amilcar,
Thank you for your feedback.
Thanks for the insight; I decided to keep my approach as it is working fine. I was just wondering if there's a better more standard way to do it.
I am just checking your progress on the issue that you are having.
If you require any further assistance please do not hesitate to ask.
I have been investigating your question and contacting with our development team. DataValueChanged feature could be helpful in your scenario only if you know in advance that the number of changes that you will make, will be small, since the control keeps the last ‘n’ of number changes in memory. There is no reliable a way to set ‘n’ to a value that ensures the initial value will be preserved in the history and that the history will not grow to a point where memory consumption becomes an issue. If you only want only to tracking changes that the user makes via editing cells, another available approach is to use the Tag property of the Cell, so you could handle the EditModeStarted event. If the Tag property of the Cell is null then get the value and set it on the Tag property and bind your Tooltip to this Tag property.
?