Пример #1
0
        private void ConfigureGridColumns()
        {
            DataGridViewColumnCollection columns = itemsGrid.Columns;

            columns[0].Visible = false;

            columns[1].HeaderText = "Item Name";
            columns[1].Width      = 230;

            columns.RemoveAt(2);

            DataGridViewComboBoxColumn column = new DataGridViewComboBoxColumn();

            column.DataPropertyName = "UoMID";
            column.DataSource       = unitsTable;
            column.DisplayMember    = "UnitName";
            column.ValueMember      = "ID";
            column.ValueType        = SqlDbType.Int.GetType();
            column.Width            = 120;
            column.Name             = "UoMID";
            column.HeaderText       = "Measurement Unit";
            column.DisplayStyleForCurrentCellOnly = true;

            columns.Insert(2, column);

            DataGridViewTextBoxColumn textColumn = (DataGridViewTextBoxColumn)columns[3];

            textColumn.HeaderText = "Price Per Unit (Rs.)";
            textColumn.Width      = 120;
            textColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            textColumn.DefaultCellStyle.Format    = "N2";
        }
Пример #2
0
        /// <summary>
        /// This method handle the blob values to not show it as garbage or unreadable data
        /// </summary>
        /// <param name="gridView">The gridview that can have blob values</param>
        public static void SanitizeBlobs(ref DataGridView gridView)
        {
            if (gridView == null)
            {
                return;
            }

            DataGridViewColumnCollection coll = gridView.Columns;
            var isColBlob = new bool[coll.Count];

            for (int i = 0; i < coll.Count; i++)
            {
                DataGridViewColumn col = coll[i];
                if (!(col is DataGridViewImageColumn))
                {
                    continue;
                }
                coll.Insert(i, new DataGridViewTextBoxColumn()
                {
                    DataPropertyName = col.DataPropertyName,
                    HeaderText       = col.HeaderText,
                    ReadOnly         = true
                });
                coll.Remove(col);
                isColBlob[i] = true;
            }

            // Adding this delegate to the CellFormating handler we can customize the format suitable for display blob values.
            // This format will be applied when the grid cells are being painted, that's why is added as a delegate.
            gridView.CellFormatting += delegate(object sender, DataGridViewCellFormattingEventArgs e)
            {
                if (e.ColumnIndex == -1)
                {
                    return;
                }
                if (isColBlob[e.ColumnIndex])
                {
                    if (e.Value == null || e.Value is DBNull)
                    {
                        e.Value = "<NULL>";
                    }
                    else
                    {
                        e.Value = "<BLOB>";
                    }
                }
            };
        }
 public override void Insert(int index, IGridColumn item)
 {
     _base.Insert(index, GridColumn.ToNativeColumn(item));
 }