Note that there are some explanatory texts on larger screens.

plurals
  1. POCopy DataGridView content to a multiple TextBoxes
    primarykey
    data
    text
    <p>I have a DataGridView with 3 columns, and I want that when I click a cell, the content from it will be copied to 2 different textboxes and 1 combobox. So far, the only thing I've come into is something like this:</p> <pre><code> private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { dataGridView1.Rows.CopyTo = txtCveMun.Text; } </code></pre> <p>The above doesn't work at all, it's just something I came into messing around with the libraries. So, what should I do? Thanks!</p> <p>If anyone cares, this is the method I fill up my DataGridView:</p> <pre><code>private void CargaDataGridView() { conexion.Open(); try { cmd.CommandText = "SELECT m.cvemunicipio, m.nombre AS NombreA, e.nombre AS NombreB FROM tbMunicipios m INNER JOIN tbEstados e ON m.CveEstado = e.CVeEstado"; rd = cmd.ExecuteReader(); while (rd.Read()) { this.dataGridView1.Rows.Add(rd.GetValue(0), rd.GetValue(1), rd.GetValue(2)); } conexion.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } </code></pre> <p><strong>EDIT</strong></p> <p>The complete answer for this is</p> <pre><code>private void dataGridView1_DoubleClick(object sender, EventArgs e) { txtCveMun.Text = dataGridView1.SelectedRows[0].Cells["Column1"].Value.ToString(); txtNomMun.Text = dataGridView1.SelectedRows[0].Cells["Column2"].Value.ToString(); cbEstado.Text = dataGridView1.SelectedRows[0].Cells["Column3"].FormattedValue.ToString(); } </code></pre>
    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