Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void initialiseDataGridView(Part part, string batchNumber){
- dataCollection = new DataCollection(part.name, batchNumber);
- dataCollectionSource = new BindingSource(dataCollection, null);
- serialConDataGrid.DataSource = dataCollectionSource;
- serialConDataGrid.AutoGenerateColumns = false;
- // Add columns
- DataGridViewCheckBoxColumn selectedCol = new DataGridViewCheckBoxColumn(false);
- selectedCol.HeaderText = "Selected";
- DataGridViewColumn runNumberCol = new DataGridViewColumn();
- runNumberCol.HeaderText = "Run Number";
- serialConDataGrid.Columns.Clear();
- serialConDataGrid.Columns.Add(selectedCol);
- serialConDataGrid.Columns.Add(runNumberCol);
- // How can I specify which values to populate into the column cells here?
- }
- public class Fruit
- {
- public string Name { get; set; }
- public Color Color { get; set; }
- public Fruit(string name, Color color)
- {
- Name = name;
- Color = color;
- }
- }
- // The list of objects
- List<Fruit> fruit = new List<Fruit>( )
- {new Fruit("Apple",Color.Red),
- new Fruit("Orange",Color.Orange),
- new Fruit("Pear",Color.Green)};
- BindingSource source = new BindingSource(fruit, null);
- dataGridView1.AutoGenerateColumns = false;
- DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
- column.HeaderText = "Name Of Fruit";
- column.DataPropertyName = "Name"; // Name of the property in Fruit
- dataGridView1.Columns.Add(column);
- DataGridViewTextBoxColumn colorColumn = new DataGridViewTextBoxColumn();
- colorColumn.HeaderText = "Color";
- colorColumn.DataPropertyName = "Color"; // Name of the property in Fruit
- dataGridView1.Columns.Add(colorColumn);
- dataGridView1.DataSource = source;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement