Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8600967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:44:11+00:00 2026-06-12T01:44:11+00:00

Here is a method I am using to create a datagridview and then add

  • 0

Here is a method I am using to create a datagridview and then add 2 comboboxes. Three DataTables get loaded from other classes.

public void GetWorkorderItems()
        {
        Workorders wo = new Workorders();
        ItemTable = wo.LoadWorkorderItemsTable(_ID);


        this.datagridWorkorderItems.DataSource = ItemTable;
        this.datagridWorkorderItems.AutoGenerateColumns = true;
        this.datagridWorkorderItems.Columns[0].Visible = false;
        this.datagridWorkorderItems.Columns[1].HeaderText = "Qty";
        this.datagridWorkorderItems.Columns[1].Width = 100;
        this.datagridWorkorderItems.Columns[2].HeaderText = "Part";
        this.datagridWorkorderItems.Columns[2].Width = 100;
        this.datagridWorkorderItems.Columns[3].HeaderText = "Labor";
        this.datagridWorkorderItems.Columns[3].Width = 100;
        this.datagridWorkorderItems.Columns[4].HeaderText = "Price";
        this.datagridWorkorderItems.Columns[4].Width = 150;
        this.datagridWorkorderItems.Columns[5].HeaderText = "Description";
        this.datagridWorkorderItems.Columns[5].Width = 150;

        Parts part = new Parts();
        DataTable partdata = new DataTable();
        partdata = part.LoadPartTable();
        DataGridViewComboBoxColumn pcb = (DataGridViewComboBoxColumn)this.datagridWorkorderItems.Columns[2];
        pcb.DataSource = partdata;
        pcb.DisplayMember = "PartName";
        pcb.ValueMember = "PartID";
        datagridWorkorderItems.Columns.Add(pcb);

        Labor labor = new Labor();
        DataTable data = new DataTable();
        data = labor.LoadLaborTable();
        DataGridViewComboBoxColumn cb = (DataGridViewComboBoxColumn)this.datagridWorkorderItems.Columns[3];
        cb.DataSource = data;
        cb.DisplayMember = "LaborItem";
        cb.ValueMember = "LaborID";
        datagridWorkorderItems.Columns.Add(cb);

        }

When the code gets to the creation of the DataGridViewComboBox object the code exits the method and does not add or load the comboboxes. There is no exception thrown either.

Any help?

EDIT****
DataGridViewTextBoxColumn col0 = (DataGridViewTextBoxColumn)this.datagridWorkorderItems.Columns[0];
this.datagridWorkorderItems.Columns[0].DataPropertyName = “WOItemID”;
this.datagridWorkorderItems.Columns[0].Visible = false;
this.datagridWorkorderItems.Columns.Add(col0);

        DataGridViewTextBoxColumn col1 = (DataGridViewTextBoxColumn)this.datagridWorkorderItems.Columns[1];
        this.datagridWorkorderItems.Columns[1].DataPropertyName = "Quantity";
        this.datagridWorkorderItems.Columns[1].HeaderText = "Qty";
        this.datagridWorkorderItems.Columns[1].Width = 100;
        this.datagridWorkorderItems.Columns.Add(col1);

        DataGridViewComboBoxColumn pcb = (DataGridViewComboBoxColumn)this.datagridWorkorderItems.Columns[2];
        pcb.DataSource = partdata;
        pcb.DisplayMember = "PartName";
        pcb.ValueMember = "PartID";
        datagridWorkorderItems.Columns.Add(pcb);

This might be the way to build the columns if I understand.

***Fixed code that works******

public void GetWorkorderItems()
        {
        Workorders wo = new Workorders();
        ItemTable = wo.LoadWorkorderItemsTable(_ID);

        Parts part = new Parts();
        DataTable partdata = new DataTable();
        partdata = part.LoadPartTable();

        Labor labor = new Labor();
        DataTable data = new DataTable();
        data = labor.LoadLaborTable();


        this.datagridWorkorderItems.AutoGenerateColumns = false;

        DataGridViewTextBoxColumn col0 = new DataGridViewTextBoxColumn();
        col0.DataPropertyName = "WOItemID";
        col0.Visible = false;
        this.datagridWorkorderItems.Columns.Add(col0);

        DataGridViewTextBoxColumn col1 = new DataGridViewTextBoxColumn();
        col1.DataPropertyName = "Quantity";
        col1.HeaderText = "Qty";
        col1.Width = 100;
        this.datagridWorkorderItems.Columns.Add(col1);

        DataGridViewComboBoxColumn col2 = new DataGridViewComboBoxColumn();
        col2.DataPropertyName = "PartID";
        col2.DataSource = partdata;
        col2.DisplayMember = "PartName";
        col2.ValueMember = "PartID";
        col2.HeaderText = "Part";
        datagridWorkorderItems.Columns.Add(col2);

        DataGridViewComboBoxColumn col3 = new DataGridViewComboBoxColumn();
        col3.DataPropertyName = "LaborID";
        col3.DataSource = data;
        col3.DisplayMember = "LaborItem";
        col3.ValueMember = "LaborID";
        col3.HeaderText = "Labor";
        datagridWorkorderItems.Columns.Add(col3);

        DataGridViewTextBoxColumn col4 = new DataGridViewTextBoxColumn();
        col4.DataPropertyName = "Price";
        col4.HeaderText = "Price";
        col4.Width = 100;
        this.datagridWorkorderItems.Columns.Add(col4);

        DataGridViewTextBoxColumn col5 = new DataGridViewTextBoxColumn();
        col5.DataPropertyName = "Description";
        col5.HeaderText = "Description";
        col5.Width = 100;
        this.datagridWorkorderItems.Columns.Add(col5);

        this.datagridWorkorderItems.DataSource = ItemTable;

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:44:12+00:00Added an answer on June 12, 2026 at 1:44 am

    Try something like this:

    public ExampleForm()
        {
            InitializeComponent();
            datagridWorkorderItems.AutoGenerateColumns = false;
    
            DataGridViewTextBoxColumn qtyColumn = new DataGridViewTextBoxColumn();
            qtyColumn.DataPropertyName = "Qty";
            qtyColumn.HeaderText = "Qty";
            datagridWorkorderItems.Columns.Add(qtyColumn);
    
            DataGridViewComboBoxColumn partColumn = new DataGridViewComboBoxColumn();
            partColumn.Items.Add(new Part() { ID = 0, PartName = "Tire" });
            partColumn.Items.Add(new Part() { ID = 1, PartName = "Motor" });
            partColumn.HeaderText = "Part";
            partColumn.DataPropertyName = "PartID";
            partColumn.ValueMember = "ID";
            partColumn.DisplayMember = "PartName";
            datagridWorkorderItems.Columns.Add(partColumn);
    
            List<WorkOrder> workOrders = new List<WorkOrder>();
            workOrders.Add(new WorkOrder() { Qty = 0, PartID = 0});
            workOrders.Add(new WorkOrder() { Qty = 2, PartID = 1});
    
            datagridWorkorderItems.DataSource = workOrders;
        }
    }
    
    public class WorkOrder
    {
        public int Qty { get; set; }
        public int PartID { get; set; }
    }
    
    public class Part
    {
        public int ID { get; set; }
        public string PartName { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So here is a method I'm using to create form objects: protected function _getForm($form,
I get the following error message when from a script I'm using to create
I'm trying to create UITableView with vertical gridlines, using method described here: http://www.iphonedevx.com/?p=153 .
I created a login page using spring_security_check. Here: <form name='f' action=/sec_test/j_spring_security_check method='POST'> <table> <tr>
Using the method presented here: http://cslibrary.stanford.edu/110/BinaryTrees.html#java 12. countTrees() Solution (Java) /** For the key
I am using Jon Skeet's ReadFully method implemented here: public static byte[] ReadFully(Stream stream)
Currently I'm using the helper methods outlined here to return some JSON from my
I'm trying to create a zipfile in a MVC method using the DotNetZip components.
I have called a method using a secondary thread. From inside the method i
I am trying to re-write a method using TDD. Here is the original method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.