예제 #1
0
        public static void SetFormatCellEventHandler(this DataGrid dataGrid, FormatCellEventHandler formatCellEventHandler)
        {
            if (dataGrid == null)
            {
                throw new ArgumentNullException(nameof(dataGrid));
            }

            if (dataGrid.DataSource == null)
            {
                return;
            }


            if (dataGrid.TableStyles.Count > 0)
            {
                dataGrid.TableStyles.Clear();
            }


            if (dataGrid.DataSource is DataTable)
            {
                dataGrid.TableStyles.Add(CreateDataGridTableStyleWithCellFormat((DataTable)dataGrid.DataSource, formatCellEventHandler));
            }
            else if (dataGrid.DataSource is DataSet)
            {
                foreach (DataTable dataTable in ((DataSet)dataGrid.DataSource).Tables)
                {
                    dataGrid.TableStyles.Add(CreateDataGridTableStyleWithCellFormat(dataTable, formatCellEventHandler));
                }
            }
        }
예제 #2
0
        private void OnSetCellFormat(DataGridFormatCellEventArgs e)
        {
            FormatCellEventHandler handler = SetCellFormat;

            if (handler != null)
            {
                handler(this, e);
            }
        }
예제 #3
0
        public static void SetFormatCellEventHandler(this DataGridTableStyle dataGridTableStyle, FormatCellEventHandler formatCellEventHandler)
        {
            if (dataGridTableStyle == null)
            {
                throw new ArgumentNullException(nameof(dataGridTableStyle));
            }
            if (formatCellEventHandler == null)
            {
                throw new ArgumentNullException(nameof(formatCellEventHandler));
            }

            foreach (DataGridColumnStyle dataGridColumnStyle in dataGridTableStyle.GridColumnStyles)
            {
                if (dataGridColumnStyle is IFormattableColumn)
                {
                    ((IFormattableColumn)dataGridColumnStyle).SetCellFormat += new FormatCellEventHandler(formatCellEventHandler);
                }
            }
        }
예제 #4
0
        public static DataGridTableStyle CreateDataGridTableStyleWithCellFormat(this DataTable dataTable, FormatCellEventHandler formatCellEventHandler, string nullText)
        {
            var dataGridTableStyle = new DataGridTableStyle();

            dataGridTableStyle.MappingName = dataTable.TableName;

            foreach (DataColumn col in dataTable.Columns)
            {
                DataGridColumnStyle column = null;
                if (col.DataType == typeof(bool))
                {
                    column = new FormattableBooleanColumn();
                    ((FormattableBooleanColumn)column).SetCellFormat += new FormatCellEventHandler(formatCellEventHandler);
                }
                else
                {
                    column = new FormattableTextBoxColumn();
                    ((FormattableTextBoxColumn)column).SetCellFormat += new FormatCellEventHandler(formatCellEventHandler);
                }
                column.MappingName = col.ColumnName;
                column.HeaderText  = col.Caption;
                //column.Width = 30;
                if (nullText == null)
                {
                    column.NullText = nullText;
                }

                dataGridTableStyle.GridColumnStyles.Add(column);
            }
            return(dataGridTableStyle);
        }
예제 #5
0
 public static DataGridTableStyle CreateDataGridTableStyleWithCellFormat(this DataTable dataTable, FormatCellEventHandler formatCellEventHandler)
 {
     return(CreateDataGridTableStyleWithCellFormat(dataTable, formatCellEventHandler, null));
 }