Example #1
0
        private static void InitDataGridView(
            DataGridView exten)
        {
            var decimalValue = new DataGridViewTextBoxColumn
            {
                DataPropertyName = "ItemDecimal",
                HeaderText       = "Decimal",
                DefaultCellStyle =
                {
                    Format         = "N0",
                    FormatProvider = new CultureInfo("en-us")
                }
            };

            exten.Columns.Clear();

            exten.AllowUserToAddRows  = false;
            exten.AutoGenerateColumns = false;

            exten.RowHeadersVisible       = true;
            exten.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
            //exten.RowHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;

            exten.Columns.Add(new DataGridViewTextBoxColumn {
                DataPropertyName = "Id", Visible = false
            });
            exten.Columns.Add(new DataGridViewTextBoxColumn {
                DataPropertyName = "ItemString", HeaderText = "String"
            });
            exten.Columns.Add(new DataGridViewTextBoxColumn {
                DataPropertyName = "ItemInt32", HeaderText = "Int32"
            });
            exten.Columns.Add(new DataGridViewCheckBoxColumn {
                DataPropertyName = "ItemBoolean", HeaderText = "Boolean"
            });

            exten.Columns.Add(decimalValue);

            //exten.Columns.Add(new DataGridViewTextBoxColumn { DataPropertyName = "ItemDateTime", HeaderText = "DateTime" });
            exten.Columns.Add(new DataGridViewCalendarColumn {
                DataPropertyName = "ItemDateTime", HeaderText = "DateTime"
            });

            exten.DataBindingComplete += (s, e) => exten.AutoNumberRowsForGridView();
        }