3
I can fill a combobox with Datatable, but in my case I need to fill 2 combobox and 1 checkedboxlist with data from a Mysql comic
//formulário cadastro
private void frmCadastroRecibo_Load(object sender, EventArgs e)
{
Classes.DBconect con = new Classes.DBconect();
string sqlc = "SELECT * FROM cliente";
DataTable dtc = new DataTable();
MySqlDataReader drc = con.returnDataR(sqlc);
dtc.Load(drc);
cmbCliente.DisplayMember = "nome";
cmbCliente.ValueMember = "id";
cmbCliente.DataSource = dtc;
}
//classe de ligação aplicação e bd
public MySqlDataReader returnDataR(string querySql)
{
str_sql = querySql;
MySqlConnection exec = new MySqlConnection();
exec = abrirBanco();
MySqlCommand comando = new MySqlCommand();
comando.CommandText = str_sql.ToString();
comando.Connection = exec;
MySqlDataReader sqlReader = comando.ExecuteReader();
return sqlReader;
}
How can I do that?
I usually make a generic method for this. Then I pass in the argument of the method a parameter of the type of combobox and also of the checklistbox. It can be an overcharged method. One for combo and one for Checklist.
– pnet
unfortunately I don’t know how to do this.
– henrique
you need to fill the combobox s and the checkedboxlist with the same data?
– Richard Dias
Just replicate the solution you already have for another
ComboBox
and to theCheckedListBox
, since the allocation of theDataSource
is exactly the same!– João Martins