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 8035385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:17:33+00:00 2026-06-05T02:17:33+00:00

Let’s say i have two tables: work_hours work_hours_id | date | _project_id 1 1.2.

  • 0

Let’s say i have two tables:

 work_hours
 work_hours_id | date  | _project_id
     1            1.2.      10
     2            1.2.      11
     3            1.2.      10 

 project
 project_id | project_name
    10           pr1
    11           pr2
    12           pr3

In DataGridView i want to see this:

 work_hours_id | date | _person_id | project_name(DataGridViewComboBoxColumn)
     1            1.2.     10            pr1
     2            1.2.     11            pr2
     3            1.2.     10            pr1

1. How can i do that?
2. Is possible to save changes in table work_hours, if i change pr1 (work_hours_id = 3) to pr3 (DataGridViewComboBoxColumn) with SqlCommandBuilder?

 string query = "SELECT work_hours.work_hours_id, work_hours.date FROM work_hours
           LEFT OUTER JOIN project ON work_hours._project_id = project.project_id ORDER BY work_hours.date;
         SELECT * FROM project ORDER BY project_name";

            SqlCommand sqlcmd = new SqlCommand(query, conn);
            da = new SqlDataAdapter(query, connectionString);
            cBuilder = new SqlCommandBuilder(da);
            dt = new DataTable();
            ds = new DataSet();
            da.Fill(dt);
            da.Fill(ds);

            DataGridViewComboBoxColumn columnCb = new DataGridViewComboBoxColumn();
            columnCb.DataPropertyName = "_project_id";

            columnCb.DataSource = ds.Tables[1];
            columnCb.ValueMember = "project_id";
            columnCb.DisplayMember = "project_name";

            bSource = new BindingSource();
            bSource.DataSource = dt;
            dataGridView1.DataSource = bSource;
            dataGridView1.Columns.Add(columnCb);

Here is example:

  • 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-05T02:17:34+00:00Added an answer on June 5, 2026 at 2:17 am

    if i don’t misunderstand you want to set the datagridview’s combobox column’s datasource..You can set by this :

    /// if you use OfType Method then you will get advantage of to use as normal control
    /// means this method will give you advantage of can use all method and properties
    /// of the control which you want to implement in DataGridView
    
    /// Controls.OfType method will check all the columns and get an array with 
    /// what you give as search criteria..here, the criteria is ComboboxColumn..
    /// depends of your need you can give comboboxcell also..
    
    /// Element at method selects the zero based index in array which filtered by criteria
    /// if you use only one of the given type then you can use .First() instead of .ElementAt()
    
    
    yourDataGridViewName.Controls.OfType<DataGridViewComboBoxColumn>()
    .ElementAt(indexNoOfTheDGVComboBox).DataSource = YourDataRetrievingMethod; 
    //i.e. ds.Tables[indexNoOfTheTable].Columns[IndexOfTheColumn]
    
    /// and you can set DisplayMember and ValueMember as the same way.. 
    /// i give combocell and combocolumn together to show the syntax.
    
    yourDataGridViewName.Controls.OfType<DataGridViewComboBoxCell>()
    .ElementAt(0).DisplayMember = "YourDisplay";
    
    yourDataGridViewName.Controls.OfType<DataGridViewComboBoxCell>()
    .ElementAt(0).ValueMember = "YourValue"; 
    

    About the second Question.. if you ask me then i prefer : To control “accidentally savings” put a buttonCell at the end of the row..when user change something on row should click the save button..And then in your button click method you can save changes as normal insert or update method..

    just 2 differences there..

    1-) you need to use Cell_Click Event and to be sure that is button check with OfType() method instead of normal Button _Click event

    2-) Depends to project needs, you will need to get DataGridView’s RowIndex and / or Cell Address() before to get and pass values to the SQLQuery

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say i have two tables in db: Car and Part. Car owns arbitrialy
Let's say I have two tables orgs and states orgs is (o_ID, state_abbr) and
Let's say I have a structure named vertex with a method that adds two
Let's say I have window.open (without name parameter), scattered in my project and I
Let's say that I have a date in R and it's formatted as follows.
Let's say I have a due date and a reminder timespan . How do
Let say I have two UIViews: View1: - bounds: 0, 0, 20, 20 -
Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting
Let's say I've got two tables: one with customer data, one with location data.
Let's say we have a table that has 2 million rows. It has two

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.