0
I have a Combobox, which run the following search:
public DataTable Localizar(String valor)
{
DataTable tabela = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("select sc.scat_loja as Loja, sc.scat_cod as Codigo , sc.scat_nome as Descricao, c.cat_loja as LojaCategoria, sc.cat_cod as CodigoCategoria, c.cat_nome as NomeCategoria "+
"from subcategoria sc inner join categoria c on sc.cat_cod = c.cat_cod where scat_nome like '%" +
valor + "%'", conexao.StringConexao);
da.Fill(tabela);
return tabela;
}
no on load form and so on:
private void frmCadastroSubCategoria_Load(object sender, EventArgs e)
{
this.alteraBotoes(1);
DALConexao cx = new DALConexao(DadosDaConexao.StringDeConexao);
BLLCategoria bll = new BLLCategoria(cx);
cbCatCod.DataSource = bll.Localizar("");
cbCatCod.DisplayMember = "Descricao";
cbCatCod.ValueMember = "Codigo";
// cbCatCod.SelectedValue = "LojaCategoria";
lblojaCat.Text = "";// ((ComboBox)sender).SelectedValue.ToString();
cbCatCod.Text = "";
}
where this Lojacategoria would like to bring a value that was registered to category, example code 1, description, store that was registered
Edit**
Guys, I’ll try to pass more details, Datetable, will search the categories, company she was registered (store), code (AUTO_INCREMENT) and category description.
In the load of the form I carry this information, that of the locate, in it I bring the following currently :
cbCatCod.DisplayMember = "Descricao";
cbCatCod.ValueMember = "Codigo";
brings beauty, it takes the category description and code.
but I need that in addition to this information, he bring the company that was registered (store)
cbCatCod.DisplayMember = "Descricao";
cbCatCod.ValueMember = "Codigo";
cbCatCod.ValueMember = "Loja";//aqui o codigo da empresa/loja que foi cadastrado na tabela categoria
This way it brings only the name "Store" instead of the field company/store for example 2, 3.....
as soon as changing the Selectedvaluechanged I need that field store on a label.
I think it’s become clearer now
just remembering guys, I’m starting now at c#, and watered down an idea of how to do this.
thank you all.
Your question is without a specific focus: your Combobox does not load? does not bring the information? your method Locate is harmful, uses a heavy structure, is a tip up performance...
– novic
Hello, yes loads, but only loads the code of the register that I will link example, code =1, description = category. In addition to these two fields code and description, I need the company code in which it was registered. I tried to put valueMember but it does not bring the store code. Just remembering I’m beginner, so the questions rss worth
– Rogerio Claro
cbCatCod.SelectedItem
must return a Datarowview (remember to do the Typecast) so you get all the data related to your selection https://stackoverflow.com/questions/7420043/how-to-get-selected-datarow-from-combobox– JMSlasher
thanks man, thank you
– Rogerio Claro