samesdavis Posted August 15, 2012 at 12:34 PM Report Share #472353 Posted August 15, 2012 at 12:34 PM (edited) Olá pessoal, Eu preencho as minhas combos desta forma: Private Sub Preenche_Linha() Dim RsCombo As New DataTable RsDataSet = Banco.RetornarDataSet("SELECT ID_LINHA,DS_LINHA FROM Tbl_Linhas ORDER BY DS_LINHA;") RsCombo.Columns.Add("ID_LINHA", GetType(System.String)) RsCombo.Columns.Add("DS_LINHA", GetType(System.String)) Dim dr As DataRow, NovaDr As DataRow For Each dr In RsDataSet.Tables(0).Rows() NovaDr = RsCombo.NewRow() NovaDr("ID_LINHA") = dr("ID_LINHA") NovaDr("DS_LINHA") = dr("DS_LINHA") RsCombo.Rows.Add(NovaDr) Next With Me.cboLIN_PROD .DataSource = RsCombo .DisplayMember = "DS_LINHA" .ValueMember = "ID_LINHA" End With dr = Nothing NovaDr = Nothing Me.cboLIN_PROD.Text = Nothing End Sub Só que eu gostaria de incluir mais campos nessa combo, vejam que estou colocando apenas o código e a descrição da linha de produtos nessa combo. Existe alguma forma de na hora em que eu selecionar os dados da combo já preenchida, ele trazer os outros campos sem eu ter que acessar de novo a base de dados para buscar o valor desses campos? Edited August 16, 2012 at 08:04 AM by Caça Link to comment Share on other sites More sharing options...
Caça Posted August 16, 2012 at 08:06 AM Report Share #472410 Posted August 16, 2012 at 08:06 AM Sim, basta adicionares as colunas que pretenderes no teu DataSource, depois só tens de pegar na linha selecionada e ir buscar os campos pretendidos. Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
samesdavis Posted August 16, 2012 at 10:20 AM Author Report Share #472425 Posted August 16, 2012 at 10:20 AM Teria como me mostrar? eu não entendi como fazer Eu estava fazendo assim, mas desta forma eu tinha que acessar de novo a base de dados RsDataSet = Banco.RetornarDataSet("SELECT PRE_LIN FROM Tbl_Linhas WHERE ID_LIN=" & Me.cboLIN_PROD.SelectedValue & ";") txtVL_LANC.Text = Format(RsDataSet.Tables(0).Rows(0).Item(1), "Standard") RsDataSet = Nothing Link to comment Share on other sites More sharing options...
Caça Posted August 16, 2012 at 10:26 AM Report Share #472427 Posted August 16, 2012 at 10:26 AM Primeiro adiciona as outras colunas que queres RsDataSet = Banco.RetornarDataSet("SELECT ID_LINHA,DS_LINHA, OutroCampo1, OutroCampo2 FROM Tbl_Linhas ORDER BY DS_LINHA;") Depois como estas a utilizar outro DataTable para utilizar na ComobBox, deves também criar e preencher as outras colunas RsCombo.Columns.Add("OutroCampo1", GetType(System.String)) RsCombo.Columns.Add("OutroCampo2 ", GetType(System.String)) NovaDr("OutroCampo1") = dr("OutroCampo1") NovaDr("OutroCampo2 ") = dr("OutroCampo2 ") Depois para pegar nos outros valores só tens de pegar no item selecionado tipo CType(cboLIN_PROD.SelectedItem, System.Data.DataRowView)("OutroCampo1") 'Pega no valor do OutroCampo1 actual CType(cboLIN_PROD.SelectedItem, System.Data.DataRowView)("OutroCampo2") 'Pega no valor do OutroCampo2 actual 1 Report Pedro Martins Não respondo a duvidas por PM Link to comment Share on other sites More sharing options...
samesdavis Posted August 16, 2012 at 10:35 AM Author Report Share #472429 Posted August 16, 2012 at 10:35 AM Excelente dica!!! funcionou perfeitamente, muito obrigado! Problema resolvido. 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