//include all the required namespaces using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Text; using System.Xml; namespace Test { public class TestDataGrid : System.Windows.Forms { /// /// Required designer variable. /// private System.Windows.Forms.ComboBox cmbFunctionArea; private DataTable dtblFunctionalArea; private DataGrid dgdFunctionArea; /// /// public constructor /// public TestDataGrid() { //automatically generated by the VS Designer //creates the object of the above designer variables InitializeComponent(); PopulateShortlistGrid(); } //call this below method after initialize component private void PopulateShortlistGrid() { DataColumn dtcShortlist; //Combo box control added as discussed above cmbWorkflow = new ComboBox(); cmbWorkflow.Cursor = System.Windows.Forms.Cursors.Arrow; cmbWorkflow.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; cmbWorkflow.Dock = DockStyle.Fill; dtbShortlist = new DataTable("ShortList"); string strColumnName = null; string []arrstrSearch = null; arrstrSearch = new string[4]; arrstrSearch[1] = "Candidate Code"; arrstrSearch[2] = "Candidate Name"; arrstrSearch[3] = "Workflow"; //Adding a check box control in the first column of the data grid //create a Data Column object with Column Name as “Select” DataColumn dtcCheck = new DataColumn("Select"); //Set the data type of the checkbox i.e. to Boolean dtcCheck.DataType = System.Type.GetType("System.Boolean"); //Set its default value as false dtcCheck.DefaultValue = false; //add the above check box column to the data table dtbShortlist.Columns.Add(dtcCheck); //Also add the other three columns i.e. Candidate Code, Candidate //Name and Workflow respectively for(int intI=1; intI< 4;intI++) { strColumnName = arrstrSearch[intI]; dtcShortlist = new DataColumn(strColumnName); dtcShortlist.DataType = System.Type.GetType("System.String"); dtbShortlist.Columns.Add(dtcShortlist); } dgdShortList.DataSource = dtbShortlist; } } }