this.datagrid.QueryUnboundColumnValue += datagrid_QueryUnboundColumnValue; void datagrid_QueryUnboundColumnValue(object sender, GridUnboundColumnEventsArgs e) { var value = e.Value.ToString(); DateTime dt = Convert.ToDateTime(value); e.Value = "Datum:" + dt.ToString("M.d.yyyy"); } |
Format="'{ValidFrom} - {ValidTo} (von {DelegatorSalutation} {DelegatorFirstname} {DelegatorLastname})'"
In this case the grid displays: 01.08.2016 00:00:00 - 15.08.2016 00:00:00 (von Herrn Max Müller)But it should be: 01.08.2016 - 15.08.2016 (von Herrn Max Müller)
void datagrid_QueryUnboundColumnValue(object sender, GridUnboundColumnEventsArgs e) { var data = e.Value as BusinessObjects; string validFrom=null, validTo=null; if (data != null) { validFrom = data.ValidFrom.ToString("M.d.yyyy"); validTo = data.ValidTo.ToString("M.d.yyyy"); } e.Value = validFrom + "-" + validTo; } |
Format="'{ValidFrom} - {ValidTo} (von {DelegatorSalutation} {DelegatorFirstname} {DelegatorLastname})'"
The grid displays: 01.08.2016 00:00:00 - 15.08.2016 00:00:00 (von Herrn Max Müller)But it should display: 01.08.2016 - 15.08.2016 (von Herrn Max Müller)
Format="'{ValidFrom(M.d.yyyy)} - {ValidTo(M.d.yyyy)} (von {DelegatorSalutation} {DelegatorFirstname} {DelegatorLastname})'"
<interactivity:Interaction.Behaviors> <local:InitialSetupBehaviour/> </interactivity:Interaction.Behaviors> public class InitialSetupBehaviour : Behavior<SfDataGrid> { protected override void OnAttached() { this.AssociatedObject.QueryUnboundColumnValue += AssociatedObject_QueryUnboundColumnValue; } void AssociatedObject_QueryUnboundColumnValue(object sender, GridUnboundColumnEventsArgs e) { var data = e.Value as BusinessObjects; string validFrom = null, validTo = null; if (data != null) { validFrom = data.ValidFrom.ToString("M.d.yyyy"); validTo = data.ValidTo.ToString("M.d.yyyy"); } e.Value = validFrom + "-" + validTo; } protected override void OnDetaching() { this.AssociatedObject.QueryUnboundColumnValue -= AssociatedObject_QueryUnboundColumnValue; } } |
public void ChangeDate(object sender, RoutedEventArgs routedEventArgs)
{
var vm = (ViewModel) DataContext;
var item = vm.GDCSource.FirstOrDefault();
if (item != null)
{
item.ValidFrom = DateTime.Today;
item.ValidTo = DateTime.Today;
}
datagrid.UpdateUnboundColumns(item);
} |
this.AssociatedObject.ItemsSourceChanged += AssociatedObject_ItemsSourceChanged; void AssociatedObject_ItemsSourceChanged(object sender, GridItemsSourceChangedEventArgs e) { this.AssociatedObject.View.RecordPropertyChanged += View_RecordPropertyChanged; } void View_RecordPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { var record=(sender as BusinessObjects); this.AssociatedObject.UpdateUnboundColumns(record); } |
Hi Jai,
requirement, I have to query database to get the value, so I have to use QueryUnboundColumnValue event, but QueryUnboundColumnValue it seems that QueryUnboundColumnValue event can only support one unbound column, how to achieve multi-unboundcolumn requirement?
void OnQueryUnboundColumnValue(object sender, GridUnboundColumnEventsArgs e)
{
if (e.UnBoundAction == UnBoundActions.QueryData)
{
//here customize based on your scenario
if (e.Column.MappingName == "GrandTotal")
{
var unitPrice = Convert.ToDouble(e.Record.GetType().GetProperty("Quantity").GetValue(e.Record));
var disCount = Convert.ToDouble(e.Record.GetType().GetProperty("Amount").GetValue(e.Record));
var save = unitPrice * disCount;
e.Value = save.ToString();
}
else if(e.Column.MappingName == "DiscountAmount")
{
var unitPrice = Convert.ToDouble(e.Record.GetType().GetProperty("Discount").GetValue(e.Record));
var disCount = Convert.ToDouble(e.Record.GetType().GetProperty("Amount").GetValue(e.Record));
var save = unitPrice * disCount / 100;
e.Value = save.ToString() + "$";
}
}
} |