Note that there are some explanatory texts on larger screens.

plurals
  1. POListBox elements are duplicated when calling the selection of an index
    primarykey
    data
    text
    <p><strong>Problem:</strong> </p> <p>I have a listbox that i fill with a dataset in that dataset i have row nombre and row cod_seg. I assign row nombre to the property display member and the cod_seg to the property display member. In the selectindexchange event of that listbox i create another dataset that bring me data that depends of the selectvalue of the listbox that happens without problem, the problem is that when i select one item of the listbox it duplicate the tem select in the listbox.</p> <p>Dont know why this is happening and i check my code 10 times...</p> <p><strong>Code: Fill Listbox</strong></p> <pre><code>private void FillData(int cs) { CS = cs; ds.Clear(); string cmd = "select CompaniaSeguro.Nombre,CompaniaSeguro.Telefono,CompaniaSeguro.Email from CompaniaSeguro where CompaniaSeguro.Cod_Comp = " + cs.ToString(); ds = mytool.Execute(cmd); if (ds.Tables[0].Rows.Count &gt; 0) { txtNC.Text = ds.Tables[0].Rows[0]["Nombre"].ToString(); if (ds.Tables[0].Rows[0]["Telefono"].ToString().Trim().Length == 0) txtTelefono.Text = "No Asignado"; else txtTelefono.Text = ds.Tables[0].Rows[0]["Telefono"].ToString(); if (ds.Tables[0].Rows[0]["Email"].ToString().Trim().Length == 0) txtEmail.Text = "No Asignado"; else txtEmail.Text = ds.Tables[0].Rows[0]["Email"].ToString(); } ds.Clear(); cmd = "select Seguro.Cod_Seg , Seguro.Nombre from Seguro where Seguro.Cod_Comp = " + cs.ToString(); ds = mytool.Execute(cmd); if (ds.Tables[0].Rows.Count &gt; 0) { listBox1.DataSource = ds.Tables[0]; listBox1.DisplayMember = "Nombre"; listBox1.ValueMember = "Cod_Seg"; finish = true; } } </code></pre> <p><strong>Code: Listbox selected index changed</strong></p> <pre><code>private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { if (finish == true) { if (listBox1.SelectedValue != null) { DataSet myds = new DataSet(); codS = listBox1.SelectedValue.ToString(); string cmd = "select Seguro.Nombre,Seguro.Descuento from Seguro where Seguro.Cod_Seg = " + codS; myds = mytool.Execute(cmd); if (ds.Tables[0].Rows.Count &gt; 0) { MessageBox.Show("trae"); } } } } </code></pre> <p><strong>Image</strong></p> <p><a href="http://img208.imageshack.us/img208/4499/862x.png" rel="nofollow">Image </a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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