Inheritance: System.Windows.Controls.DataGridColumn
Ejemplo n.º 1
0
        private void CreateTaskGridColumns()
        {
            Columns.Clear();

            Type t = ColumnGeneratingType;

            if (t == null)
                return;

            PropertyInfo[] infos = t.GetProperties();
            List<DataGridColumn> columns = new List<DataGridColumn>();

            bool isFirst = true;

            foreach (PropertyInfo info in infos)
            {
                GanttColumnAttribute[] atts = (GanttColumnAttribute[])info.GetCustomAttributes(typeof(GanttColumnAttribute), false);

                if (atts.Length > 0)
                {
                    GanttColumnAttribute att = atts[atts.Length - 1];

                    DataGridColumn dgc;
                    Binding bind = new System.Windows.Data.Binding(info.Name);

                    if (isFirst)
                    {
                        dgc = new GanttExpanderColumn();

                        Columns.Add(dgc);
                        (dgc as GanttExpanderColumn).RowExpandedChanged += new EventHandler<RowExpandedChangedEventArgs>(GanttDataGrid_RowExpandedChanged);
                        (dgc as GanttExpanderColumn).Binding = bind;

                        isFirst = false;
                    }
                    else
                    {
                        if (att.ColumnType == GanttColumnType.DateTime)
                        {
                            dgc = new GanttDateColumn();
                            Columns.Add(dgc);
                            bind.Mode = BindingMode.TwoWay;
                            (dgc as GanttDateColumn).Binding = bind;
                        }
                        else
                        {
                            dgc = new DataGridTextColumn();
                            Columns.Add(dgc);
                            (dgc as DataGridTextColumn).Binding = bind;
                        }
                    }

                    dgc.CanUserReorder = true;
                    dgc.CanUserResize = true;
                    dgc.CanUserSort = false;
                    dgc.Header = att.ColumnName;
                    dgc.IsReadOnly = !info.CanWrite;
                    dgc.DisplayIndex = att.ColumnIndex;

                }
            }

            //columns.Sort((a, b) => a.DisplayIndex.CompareTo(b.DisplayIndex));
            //foreach (DataGridColumn c in columns)
            //{
            //    Columns.Add(c);
            //}
        }
Ejemplo n.º 2
0
        private void CreateTaskGridColumns()
        {
            Columns.Clear();

            Type t = ColumnGeneratingType;

            if (t == null)
            {
                return;
            }

            PropertyInfo[]        infos   = t.GetProperties();
            List <DataGridColumn> columns = new List <DataGridColumn>();

            bool isFirst = true;

            foreach (PropertyInfo info in infos)
            {
                GanttColumnAttribute[] atts = (GanttColumnAttribute[])info.GetCustomAttributes(typeof(GanttColumnAttribute), false);

                if (atts.Length > 0)
                {
                    GanttColumnAttribute att = atts[atts.Length - 1];

                    DataGridColumn dgc;
                    Binding        bind = new System.Windows.Data.Binding(info.Name);

                    if (isFirst)
                    {
                        dgc = new GanttExpanderColumn();

                        Columns.Add(dgc);
                        (dgc as GanttExpanderColumn).RowExpandedChanged += new EventHandler <RowExpandedChangedEventArgs>(GanttDataGrid_RowExpandedChanged);
                        (dgc as GanttExpanderColumn).Binding             = bind;

                        isFirst = false;
                    }
                    else
                    {
                        if (att.ColumnType == GanttColumnType.DateTime)
                        {
                            dgc = new GanttDateColumn();
                            Columns.Add(dgc);
                            bind.Mode = BindingMode.TwoWay;
                            (dgc as GanttDateColumn).Binding = bind;
                        }
                        else
                        {
                            dgc = new DataGridTextColumn();
                            Columns.Add(dgc);
                            (dgc as DataGridTextColumn).Binding = bind;
                        }
                    }

                    dgc.CanUserReorder = true;
                    dgc.CanUserResize  = true;
                    dgc.CanUserSort    = false;
                    dgc.Header         = att.ColumnName;
                    dgc.IsReadOnly     = !info.CanWrite;
                    dgc.DisplayIndex   = att.ColumnIndex;
                }
            }

            //columns.Sort((a, b) => a.DisplayIndex.CompareTo(b.DisplayIndex));
            //foreach (DataGridColumn c in columns)
            //{
            //    Columns.Add(c);
            //}
        }