Esempio n. 1
0
        private void configureDataGridColumns()
        {
            DataGridViewColumnCollection columns = customersGrid.Columns;

            columns[0].Visible = false;             // hide the ID column

            DataGridViewColumn column = columns[1]; //customer name

            column.HeaderText = "Name";
            column.Width      = 150;

            columns[2].HeaderText = "Phone Numbers";
            columns[2].Width      = 90;

            column            = columns[3];
            column.HeaderText = "Mobile Numbers";
            column.Width      = 90;

            column            = columns[4];
            column.HeaderText = "Address";
            column.Width      = 100;

            column            = columns[5];
            column.HeaderText = "City";
            column.Width      = 50;

            columns.Remove("OpeningBalance");
            columns.Remove("BalanceType");

            columns[6].HeaderText = "Notes";
            columns[6].Width      = 120;

            column              = columns[7];
            column.HeaderText   = "Opening Balance (Rs.)";
            column.Width        = 140;
            column.DisplayIndex = 2;
            column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
        }
Esempio n. 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>";
                    }
                }
            };
        }