Technology computers-hardware

CSharp Controls to DataGridView

    Text Box Control

    • A text box control is used to capture information in a computer program. A "DataGridView" control allows programmers to add a column of text boxes by adding a "DataGridViewTextBoxColumn." This column can be used to capture text-based values such as numbers and strings for each row. The following is an example of how to use this type of control:

      DataGridViewTextBoxColumn titleColumn =
      new DataGridViewTextBoxColumn();
      titleColumn.HeaderText = "Title";
      titleColumn.AutoSizeMode =
      DataGridViewAutoSizeColumnMode.AllCellsExceptHeader;

    Check Box Control

    • A check box control is used to mark data as true or false in a computer program. The "DataGridViewCheckBoxColumn" is used to display a check box control in the cells of each row. This type of control is typically used to check a lot of cell values to perform bulk operations such as checking and deleting emails. The following is an example of how to set up a check box control in a DataGridView control to mark employees out of office:

      private void AddOutOfOfficeColumn()
      {
      DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
      {
      column.HeaderText = ColumnName.OutOfOffice.ToString();
      column.Name = ColumnName.OutOfOffice.ToString();
      column.AutoSizeMode =
      DataGridViewAutoSizeColumnMode.DisplayedCells;
      column.FlatStyle = FlatStyle.Standard;
      column.ThreeState = true;
      column.CellTemplate = new DataGridViewCheckBoxCell();
      column.CellTemplate.Style.BackColor = Color.Beige;
      }

      DataGridView1.Columns.Insert(0, column);
      }

    Image Control

    • The DataGridViewImageColumn is used to display images. Often, image columns are populated automatically from a data source such as a database. This data type will add an image control to each cell of this data type, which enables you to display images for every new row. One example of when to use this control may be in applications displaying ads. The first column will display an image, and the rest will display the description of the ad. The following shows how to create the image column:

      private void CreateColumns()
      {
      DataGridViewImageColumn imageColumn;
      int columnCount = 0;
      do
      {
      Bitmap unMarked = blank;
      imageColumn = new DataGridViewImageColumn();

      //Add twice the padding for the left and
      //right sides of the cell.
      imageColumn.Width = x.Width + 2 * bitmapPadding + 1;

      imageColumn.Image = unMarked;
      dataGridView1.Columns.Add(imageColumn);
      columnCount = columnCount + 1;
      }
      while (columnCount < 3);
      }

    Combo Box Control

    • You can also add a combo box column by using the "DataGridViewComboBoxColumn" data type. In C#, you can think of a combo box as a combination of a text box and a list box control. A list box control is a control that displays a list of items to choose from. Text can be entered or items can be chosen from a drop-down list for each row. This control is useful for data entry in fields that can only contain particular values, such as a particular type of product. The following is an example on how to add combo box column controls:

      private void AddComboBoxColumns()
      {
      DataGridViewComboBoxColumn comboboxColumn;
      comboboxColumn = CreateComboBoxColumn();
      SetAlternateChoicesUsingDataSource(comboboxColumn);
      comboboxColumn.HeaderText = "TitleOfCourtesy (via DataSource property)";
      DataGridView1.Columns.Insert(0, comboboxColumn);

      comboboxColumn = CreateComboBoxColumn();
      SetAlternateChoicesUsingItems(comboboxColumn);
      comboboxColumn.HeaderText = "TitleOfCourtesy (via Items property)";
      // Tack this example column onto the end.
      DataGridView1.Columns.Add(comboboxColumn);
      }

SHARE
RELATED POSTS on "Technology"
How to Download Pictures Into Your Computer Using an SD Card
How to Download Pictures Into Your Computer Using an SD Card
How to Transfer DOS Random Type Data From the AS400 to a PC
How to Transfer DOS Random Type Data From the AS400 to a PC
Ways to Improve the Machine
Ways to Improve the Machine
How To Change a Hard Drive In a Macbook Aluminum
How To Change a Hard Drive In a Macbook Aluminum
Printed Circuit Boards - Understanding the Requirements of the European RoHS
Printed Circuit Boards - Understanding the Requirements of the European RoHS
Asus 1005HAB Specs: Specifications Of The Asus Eee Pc 1005HAB, And Where To Find The Best Deals
Asus 1005HAB Specs: Specifications Of The Asus Eee Pc 1005HAB, And Where To Find The Best Deals
How to Troubleshoot Home Computers
How to Troubleshoot Home Computers
How to Replace the Cartridge on a Compaq IJ650 Printer
How to Replace the Cartridge on a Compaq IJ650 Printer
How to Disable a Screen Saver in Vista
How to Disable a Screen Saver in Vista
How to Remove a 939 Processor
How to Remove a 939 Processor
Can a USB Wireless Modem Be Used for Laptops?
Can a USB Wireless Modem Be Used for Laptops?
How to Remove a Screensaver Password
How to Remove a Screensaver Password
Features of Brother Cartridges
Features of Brother Cartridges
How to Check HP RAM
How to Check HP RAM
How to Clone a Laptop HD
How to Clone a Laptop HD
Innovative Technologies Used In Hp C7973a Lto-3 Tape
Innovative Technologies Used In Hp C7973a Lto-3 Tape
Pitney Bowes Printer and Toner Products for Government Use
Pitney Bowes Printer and Toner Products for Government Use
Amazing Features of the HP Compaq 6710B Battery
Amazing Features of the HP Compaq 6710B Battery
How to Refill a Canon Ink Cartridge Without Resetting
How to Refill a Canon Ink Cartridge Without Resetting
How Do I Refill a Brother Inkjet LC51BK?
How Do I Refill a Brother Inkjet LC51BK?
How to Open an Inspiron 1000
How to Open an Inspiron 1000
5 Steps to Speed Up Your Computer and Stop Slowing Down Your Life
5 Steps to Speed Up Your Computer and Stop Slowing Down Your Life
How to Get Into Compaq Advanced BIOS Information
How to Get Into Compaq Advanced BIOS Information
How to Use Decorative Fonts & Dingbats
How to Use Decorative Fonts & Dingbats

Leave Your Reply

*