cannot convert System.Windows.Controls.ComboBox to System.Window.Forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • juaruizme
    New Member
    • Sep 2021
    • 1

    cannot convert System.Windows.Controls.ComboBox to System.Window.Forms

    I need to execute display a list of values in a combo box of a database of acesss

    Code:
      private void paises_Loaded(object sender, RoutedEventArgs e)
            {
                claDatos datos = new claDatos();
                datos.LLenarCombo(pairses, "SELECT * FROM Tabla_Pais", "PAIS", "CODIGO");
            }
    but when i try to run it , it get this error cannot convert System.Windows. Controls.ComboB ox to System.Window.F orms

    there is someone who can help me

    the class does not have mistake


    and i call with a class
    Code:
    using System;
    using System.Data;
    using System.Data.OleDb;
    using System.Windows.Forms;
    
    namespace CRACKK
    {
        public class claDatos
        {
    
            OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\NET\CRACKK\FrontEndEnroll\CRACKK\Storage\DB\Datos.accdb");
    
            public DataTable Consulta(string strSql)
            {
    
                DataTable dt = new DataTable();
                OleDbDataAdapter da = new OleDbDataAdapter(strSql, conn);
                da.Fill(dt);
                return dt;
    
            }
    
            public void LLenarCombo(ComboBox combo, string strSql, string codigo, string descripcion)
            {
    
                DataTable tabla = new DataTable();
                OleDbDataAdapter da = new OleDbDataAdapter();
                da.SelectCommand = new OleDbCommand(strSql, conn);
                da.Fill(tabla);
                combo.ValueMember = codigo;
                combo.DisplayMember = descripcion;
                combo.DataSource = tabla;
            }
        }
    }
    Last edited by Banfa; Sep 6 '21, 11:54 AM. Reason: Added code tags
  • GazMathias
    Recognized Expert New Member
    • Oct 2008
    • 228

    #2
    Hi.

    Its not clear if the error you are experiencing is thrown inside of the code you have posted or not so I recommend that you add a break point and step through from the LLenarCombo call and verifty that you are passing the object you suspect.

    Additionally, shouldn't the combo box be passed by reference?

    Gaz

    Comment

    Working...