Hi,
I was working on a Xceed DataGrid on which a cell will hold two values which mean a property bounded to the cell will have property of a custom class type which has property of [ ValueText and BackGround] of which the ValueText should be bounded to display text and Background Property should be bounded to Cell Background property which works file for me. And am using the below DataTemplate to achieve this.
<DataTemplate x:Key="ShipCountryDataTemplate" DataType="{x:Type localData:DQMCell}">
<Grid VerticalAlignment="Center" HorizontalAlignment="Center" Margin="-2" removed="{Binding Path=Background, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataCell}}, Path=ActualHeight}"
Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataCell}}, Path=ActualWidth}">
<TextBlock Text="{Binding Path=ValueText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="4" />
</Grid>
</DataTemplate>
and my DataGrid Configuration is below
<egldg:EagleDataGrid x:Name="DataQualityMonitoringViewDataGrid"
ItemsSource="{Binding}"
ShowGroupPanel="True"
ShowRowNumber="True"
ReadOnly="True"
GridID="DQMVIEWDATAGRID"
AutoCreateColumns="False"
ShowRowDetailsOnDoubleClick="False"
CellEditorDisplayConditions="None"
AllowGrouping="True">
<egldg:EagleDataGrid.View>
<xcdg:TableView AllowColumnChooser="True"
ShowFixedColumnSplitter="True"
ColumnChooserSortOrder="None"
HorizontalGridLineThickness="0.1">
<xcdg:TableView.Theme>
<egltheme:DataGridAeroTheme />
</xcdg:TableView.Theme>
</xcdg:TableView>
</egldg:EagleDataGrid.View>
<egldg:EagleDataGrid.Columns>
<xcdg:Column FieldName="Status_15010" Title="{x:Static Localization:EagleResources.DG_COL_STATUS}" IsMainColumn="True" CellContentTemplate="{StaticResource DQMCELLDataTemplate}">
<xcdg:Column.GroupDescription>
<localData:DQMCellDataGridGroupDescription PropertyName="Status_15010" SortComparer="{StaticResource dQMCellComparer}"/>
</xcdg:Column.GroupDescription>
</xcdg:Column>
<xcdg:Column FieldName="RunDate_15011" Title="{x:Static Localization:EagleResources.DG_COL_RUN_DATE}" CellContentTemplate="{StaticResource DQMCELLDataTemplate}">
<xcdg:Column.GroupDescription>
<localData:DQMCellDataGridGroupDescription PropertyName="RunDate_15011" SortComparer="{StaticResource dQMCellComparer}"/>
</xcdg:Column.GroupDescription>
</xcdg:Column>
<xcdg:Column FieldName="EffectiveDate_15012" Title="{x:Static Localization:EagleResources.DG_COL_EFFECTIVE_DATE}" CellContentTemplate="{StaticResource DQMCELLDataTemplate}">
<xcdg:Column.GroupDescription>
<localData:DQMCellDataGridGroupDescription PropertyName="EffectiveDate_15012" SortComparer="{StaticResource dQMCellComparer}"/>
</xcdg:Column.GroupDescription>
</xcdg:Column>
<xcdg:Column FieldName="ListComposite_15013" Title="{x:Static Localization:EagleResources.DG_COL_LIST_COMPOSITE}" CellContentTemplate="{StaticResource DQMCELLDataTemplate}">
</egldg:EagleDataGrid.Columns>
</egldg:EagleDataGrid>
My Question is when I suppose to Group a column it group with the type DQMCELL which i have bounded to my DataTemplate DataType. but i actually need to group with that column value. which was not actually happening. help me on this to fix this issue. Any Grouping template or any idea on Xceed DataGrid you have please share it with me.
Please Let me know if any one can't understand my Question
This was my CollectionType
public class DataQualityMonitoringData : IEquatable<DQMCell>, INotifyPropertyChanged
{
private DQMCell DG_COL_RUN_DATE = new DQMCell();
public DQMCell RunDate_15011
{
get { return DG_COL_RUN_DATE; }
set
{
DG_COL_RUN_DATE = value;
OnPropertyChanged("RunDate_15011");
}
}
private DQMCell DG_COL_EFFECTIVE_DATE = new DQMCell();
public DQMCell EffectiveDate_15012
{
get { return DG_COL_EFFECTIVE_DATE; }
set
{
DG_COL_EFFECTIVE_DATE = value;
OnPropertyChanged("EffectiveDate_15012");
}
}
private DQMCell DG_COL_LIST_COMPOSITE = new DQMCell();
public DQMCell ListComposite_15013
{
get { return DG_COL_LIST_COMPOSITE; }
set
{
DG_COL_LIST_COMPOSITE = value;
OnPropertyChanged("ListComposite_15013");
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
#region IEquatable Member
public override int GetHashCode()
{
int rundate_15011 = RunDate_15011.GetHashCode();
int effectivedate_15012 = EffectiveDate_15012.GetHashCode();
int listcomposite_15013 = ListComposite_15013.GetHashCode();
return rundate_15011
^ effectivedate_15012
^ listcomposite_15013;
}
public bool Equals(DQMCell other)
{
if (Object.ReferenceEquals(other, null)) return false;
if (Object.ReferenceEquals(this, other)) return false;
return RunDate_15011.ValueText.Equals(other.ValueText)
&& EffectiveDate_15012.ValueText.Equals(other.ValueText)
&& ListComposite_15013.ValueText.Equals(other.ValueText);
}
#endregion
}
and the DQMCELL class
public class DQMCell : INotifyPropertyChanged, IEquatable<DQMCell>
{
public DQMCell()
{
this.ValueText = string.Empty;
this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Constants.REDCOLOR));
}
private string _val = string.Empty;
public string ValueText
{
get { return _val; }
set
{
_val = value;
OnPropertyChanged("ValueText");
}
}
private SolidColorBrush bg_Brush;
public SolidColorBrush Background
{
get { return bg_Brush; }
set
{
bg_Brush = value;
OnPropertyChanged("Background");
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
#region IEquatable Member
public override int GetHashCode()
{
int valueText = ValueText.GetHashCode();
int background = Background.GetHashCode();
return valueText ^ background;
}
public bool Equals(DQMCell other)
{
if (Object.ReferenceEquals(other, null)) return false;
if (Object.ReferenceEquals(this, other)) return false;
return ValueText.Equals(other.ValueText)
&& Background.Equals(other.Background);
}
#endregion
}
the Collection type of DataQualityMonitoringData is bounded to the DataGrid.
Binding Logic
List<DataQualityMonitoringData> dataQualityMonitoringData = CommonUtils.dataQualityMonitoringDataCollection.GetMainDataTable(false);
DataGridCollectionView d_view = new DataGridCollectionView(dataQualityMonitoringData);
Binding bind = new Binding();
d_view.AutoFilterMode = AutoFilterMode.And;
bind.Source = d_view;
DataQualityMonitoringViewDataGrid.SetBinding(DataGridControl.ItemsSourceProperty, bind);
I have Fixed the Grouping Issue i have implemented the below two. IComparer and DataGridGroupDescription
public class DQMCellComparer : IComparer
{
public int Compare(object x, object y)
{
if (x == null || y == null) return 0;
string dQMCell_x = x as string;
string DQMCell_y = y as string;
if (dQMCell_x.CompareTo(DQMCell_y) != 0)
{
return dQMCell_x.CompareTo(DQMCell_y);
}
return 0;
throw new NotImplementedException();
}
}
public class DQMCellDataGridGroupDescription : DataGridGroupDescription
{
public DQMCellDataGridGroupDescription()
: base()
{
}
public DQMCellDataGridGroupDescription(string propertyName)
: base(propertyName)
{
}
public override object GroupNameFromItem(object item, int level, System.Globalization.CultureInfo culture)
{
object value = base.GroupNameFromItem(item, level, culture);
try
{
DQMCell content = value as DQMCell;
if (content == null) return "";
value = content.ValueText;
}
catch (InvalidCastException)
{
}
return value;
}
}
But Still i have Sorting Issue :(