JoaoVM Posted August 26, 2014 Report Share Posted August 26, 2014 (edited) Boas malta, Tenho uma dúvida que tem a ver com sacar os dados de uma query que lista na combobox. Por exemplo, tenho uma tabela com o identificador de acesso e a sua descrição, não tem lógica colocar apenas o identificador sem a descrição, mas para inserir noutra tabela apenas quero o identificador, ou seja, mostra o identificador e a descrição mas apenas quero o valor do identificador. O que faz este código é preencher a combobox: if (conDB.State == ConnectionState.Closed) { conDB.Open(); } SqlCeCommand command_sql = new SqlCeCommand("SELECT ID_ACCESS_TYPE, DESCRIPTION FROM ACCESS_TYPE ORDER BY ID_ACCESS_TYPE ASC ", conDB); SqlCeDataReader reader_sql = command_sql.ExecuteReader(); while (reader_sql.Read()) { comboBox_permissoes.Items.Add(reader_sql["ID_ACCESS_TYPE"] + " - " + reader_sql["DESCRIPTION"]); } reader_sql.Close(); conDB.Close(); Agora ao selecionar a combo que me mostra-se os valores em separado, não tem lógica colocar apenas o id_access_type sem a descrição mas quero colocar numa variável ou label apenas o id para depois inserir numa query para inserir na tabela ou alterar etc... Este representa o botão que vai sacar os dados da combobox. Object selectitem = comboBox_colaboradores.ValueMember; label_test.Text = selecteditem; Edited August 26, 2014 by JoaoVM Link to comment Share on other sites More sharing options...
herty Posted August 26, 2014 Report Share Posted August 26, 2014 Experimenta adicionar os items a combobox assim: ComboboxItem item = new ComboboxItem(); item.Text = reader_sql["DESCRIPTION"].toString(); item.Value = reader_sql["ID_ACCESS_TYPE"].toString(); comboBox1.Items.Add(item); Link to comment Share on other sites More sharing options...
JoaoVM Posted August 26, 2014 Author Report Share Posted August 26, 2014 (edited) Não consigo fazer o ComboBoxItem e tenho o using System.Windows.Forms, será de ser windows mobile 6.5? Este código dentro do while certo? Edited August 26, 2014 by JoaoVM Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now