Hi all
My records contain unbound cells which display data based on on a presenter style and a converter. For these cells, the grid is not aware if the underlying data changes - which results in a faulty representation of my data. What I'm looking for is a way to refresh a record according to the functionality provided by WinGrid. I'm pretty sure there must be something, but I couldn't figure out where...
Thanks for your advice
Philipp
ps: I think this problem is one of the shortcomings of the BindingPath string of an unbound field. It sure would be nice if we just could use a real binding instead:<igDP:UnboundField Value="{Binding ...}" />
Hi Philipp,
I am not sure if this will help but I had the refresh problem on the grid too when the underlying data that it is bound to changed. So, I had to set the DataSource to null and set it back again to fix my problem.
Regards,
MW
MW,
Thats not really an option for me - reloading the whole data source would remarkably degrade performance as I'll be dealing with rather big collections. However, I still think there must be (or at the very least, should be ) a way to refresh a single record.
Cheers!
Hello Joe
<igDP:UnboundField Name="EditStatus" Label="" BindingPath="IsDirty"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" CellClickAction="SelectRecord" CellValuePresenterStyle="{StaticResource Grid_SimpleStatusCell}" /> </igDP:Field.Settings> </igDP:UnboundField>
And this is my style:
<Style x:Key="Grid_SimpleStatusCell" TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <StackPanel Orientation="Horizontal"> <Image Source="/Shared/Images/EditStatus/Changed.png" VerticalAlignment="Center" HorizontalAlignment="Left" Width="16" Height="16" Margin="2,0,2,0" Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Record.DataItem.IsDirty, Converter={StaticResource Control_BoolToVisibilityConverter}}" /> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style>
The style sets the Visibility property of a status image using a converter along with the IsDirty property of the underlying data item. I used your snippet in the RecordUpdated event handler of the grid. At this moment, IsDirty has changed to true. However, the converter is not being invoked so I'm still stuck... Version, btw. is 7.2 RC
"sumi" wrote in message news:13095@forums.infragistics.com... Hello Joe Unfortunately, this doesn't work - nothing happens at all. My cell looks as follows: <igDP:UnboundField Name="EditStatus" Label="" BindingPath="IsDirty"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" CellClickAction="SelectRecord" CellValuePresenterStyle="{StaticResource Grid_SimpleStatusCell}" /> </igDP:Field.Settings> </igDP:UnboundField> And this is my style: <Style x:Key="Grid_SimpleStatusCell" TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <StackPanel Orientation="Horizontal"> <Image Source="/Shared/Images/EditStatus/Changed.png" VerticalAlignment="Center" HorizontalAlignment="Left" Width="16" Height="16" Margin="2,0,2,0" Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Record.DataItem.IsDirty, Converter={StaticResource Control_BoolToVisibilityConverter}}" /> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> The style sets the Visibility property of a status image using a converter along with the IsDirty property of the underlying data item. I used your snippet in the RecordUpdated event handler of the grid. At this moment, IsDirty has changed to true. However, the converter is not being invoked so I'm still stuck... Version, btw. is 7.2 RC Thanks for your advice Philipp http://forums.infragistics.com/forums/p/1435/13095.aspx#13095
Hi Joe
I've uploaded a sample project for you - it's based on an Infragistics sample I received lately, and renders a cell's border based on the employee ID. If the ID is > 10, the border is red, otherwise, it's black. Here's the style:
<Style x:Key="MyPresenter" TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <Border BorderThickness="2" BorderBrush="{Binding Converter={StaticResource conv}}"> <ContentPresenter x:Name="PART_EditorSite" /> </Border> </ControlTemplate> </Setter.Value> </Setter></Style>
Here's the converter's method:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture){ //get the processed presenter DataRecord record = (DataRecord) value; Cell cell = record.Cells[0]; int fieldValue = (int) cell.Value; //return red if the value is above 10 return fieldValue > 10 ? Brushes.Red : Brushes.Black;}
What I'm looking for is a way to update the style once the ID has been changed, so I'm invoking CoerceValue right after the cell has been updated, but the effect is none - a black cell stays black, no matter what the cell value is. You can download thesample from here:http://www.mediafire.com/?4glly045nxl
I could imagine that this is related to the same limitation discussed here:http://forums.infragistics.com/forums/p/1682/14221.aspx#14221
Cheers,
<Border BorderThickness="2" BorderBrush="{Binding Path=Value, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource conv}}">
{
//get the processed presenter
// DataRecord record = (DataRecord) value; // Cell cell = record.Cells[0]; // int fieldValue = (int) cell.Value;
// DataRecord record = (DataRecord) value;
// Cell cell = record.Cells[0];
// int fieldValue = (int) cell.Value;
int fieldValue = (int)value; //return red if the value is above 10 return fieldValue > 10 ? Brushes.Red : Brushes.Black;
int fieldValue = (int)value;
//return red if the value is above 10
return fieldValue > 10 ? Brushes.Red : Brushes.Black;
}
Hello Joe,
Uh oh, the problem is related to the issue in the other thread
-> This is an artificial sample. I want to explicitely refresh my record *because* I cannot bind to a property that announces it's change: If it did, I wouldn't have to refresh the record manually. I can think of tons of samples where this absolutely might be the case - is there no workaround for this?
I'm still fishing for that DataRecord.Refresh method, but I'll accept any hack, now matter how dirty it might be
Hi Naveen
I see one problem with this approach though. Here is how I am using this.
if(e.Cell.Field.Name == "Fee")
DataRowView dv = e.Cell.Record.DataItem as DataRowView;
dv[
"Rate"] = Convert.ToDouble(e.Cell.Value) * .01;
e.Cell.Record.Visibility = Visibility.Collapsed;
e.Cell.DataPresenter.UpdateLayout();
e.Cell.Record.Visibility = Visibility.Visible;
After entering the value in the cell & hiting the Tab.. if the next column is a Editable it will not
go to edit mode & the horizontal scroll bar moves to the left.
Any idea how to solve these issues
Thanks
-Kiran
Thanks for your help. This worked for me
Hi, I was ably to solve the refresh records from using below code.
public static void RedrawRecord(Record record_) { if (record_ != null) { // Force Xam Grid to redraw the record so that all syles can be re-applied. record_.Visibility = Visibility.Collapsed; var presenter = DataRecordPresenter.FromRecord(record_); if (presenter != null) { presenter.UpdateLayout(); } record_.Visibility = Visibility.Visible; } }
Thanks,
Naveen
Hi
Is there any solution for refresh problem. Even i have the same problem. I bind DataView (DataTable) to grid & on editing one column I need to re-calculate the value of other 2 columns. I am doing this at the DataRow level. So changes are not reflecting unless I go click on the other columns.
Hi Can some one from infragistics comment on this? In addition to what I was doing earlier, I tried lot of options (below) but none causes the converter (which I am using to return color based on cell value) to be called. I was working with 9.1 builds. I am using latest sevice release 2010.2.20102.2045
var presenter = DataRecordPresenter.FromRecord(dataRecord);
var drCellArea = presenter.FindFirstChildByType<DataRecordCellArea>(); presenter.Visibility = Visibility.Collapsed; presenter.Visibility = Visibility.Visible; presenter.UpdateLayout(); presenter.InvalidateVisual(); drCellArea.Visibility = Visibility.Collapsed; drCellArea.Visibility = Visibility.Visible; drCellArea.UpdateLayout(); drCellArea.InvalidateVisual(); drCellArea.InvalidateProperty(Control.BackgroundProperty); _grid.Visibility = Visibility.Collapsed; _grid.Visibility = Visibility.Visible; _grid.UpdateLayout(); _grid.InvalidateVisual();