Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

XML
<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

XML
<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

C#
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;

        /// <summary>
        /// On property changed method
        /// </summary>
        /// <param name="propertyName">Property Name</param>
        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

C#
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

C#
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
C#
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 :(
Posted
Updated 17-Mar-14 22:46pm
v8
Comments
Venkatesh Mookkan 17-Mar-14 22:38pm    
Hi Navin,
Can you please tell me which field is of type of "DQMCell"? DataTemplate works based on the Data type not the control type.

Thanks
[no name] 17-Mar-14 23:16pm    
I have updated my Question. The Observerable collection of DataQualityMonitoringData is bounded to the DataGrid. and the DataQualityMonitoringData type has properties of type DQMCell. why i have designed a class like this? before we are using DataTable which bound to the DataGrid by using a IValueConvertor we will be applying color to each DataGrid cell ( The idea behind is to achieve a Heat Map kind of thing). we facing a scrolling issue in that and some slowness as well.
[no name] 18-Mar-14 4:45am    
Sir i have completed One Grouping Issue. i have updated my Question but still Sorting Issue Exist. please help me on that
[no name] 19-Mar-14 2:40am    
Sir both Grouping and sorting issue has been solved. now applying saved settings is my problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900