Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to DataGridViewComboBoxColumn set value from dataset
    primarykey
    data
    text
    <p>Let's say i have two tables:</p> <pre><code> 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 </code></pre> <p>In DataGridView i want to see this:</p> <pre><code> work_hours_id | date | _person_id | project_name(DataGridViewComboBoxColumn) 1 1.2. 10 pr1 2 1.2. 11 pr2 3 1.2. 10 pr1 </code></pre> <p><strong>1.</strong> How can i do that? <strong>2.</strong> Is possible to save changes in table <code>work_hours</code>, if i change pr1 (<code>work_hours_id = 3</code>) to pr3 (<code>DataGridViewComboBoxColumn</code>) with <code>SqlCommandBuilder</code>? </p> <pre><code> 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); </code></pre> <p><img src="https://i.stack.imgur.com/jpqtJ.jpg" alt="Here is example:"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload