combobox autocompleted in C #

0

I have a combobox that autocompleta with a query and I want to show two fields for example IdProyecto and ProyectoProyecto I want to know the form for when I search in the combo I see both the IdoProject And ProjectName next this is my code that travels and search:

DataTable dt = Datos();

        AutoCompleteStringCollection coleccion = new AutoCompleteStringCollection();
        //recorrer y cargar los items para el autocompletado
        foreach (DataRow row in dt.Rows)
        {
            coleccion.Add(Convert.ToString(row["CNombreProyecto"]));
            coleccion.Add(Convert.ToString(row["CCodigoProyecto"])); 
        }

        return coleccion;
    
asked by CHARLY 13.02.2018 в 20:58
source

1 answer

1

You are adding one below the other. If this is not wpf (which would greatly improve the solution) all you have to do is concatenate the strings to add to the combo

coleccion.Add(Convert.ToString(row["CCodigoProyecto"]) + " - " + Convert.ToString(row["CNombreProyecto"]));

With that, you're going to put together a chain of type

  

code - name

    
answered by 13.02.2018 / 22:58
source