Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void PreencherCombo(ComboBox combo)
- {
- // Usando DataTable, também é possível fazer usando BindingSource...
- DataTable tabela = new DataTable();
- tabela.Columns.Add("Id");
- tabela.Columns.Add("Name");
- DataRow registro = tabela.NewRow();
- registro["Id"] = -1;
- registro["Name"] = "";
- tabela.Rows.Add(registro);
- foreach(Sexo sexo in Sexo.List())
- {
- registro = tabela.NewRow();
- registro["Id"] = sexo.Id;
- registro["Name"] = sexo.Name;
- tabela.Rows.Add(r);
- }
- combo.Items.Clear();
- combo.ValueMember = "Id";
- combo.DisplayMember = "name";
- combo.DataSource = tabela;
- combo.SelectedIndex = -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement