csantos Posted May 28, 2013 at 09:56 AM Report #509374 Posted May 28, 2013 at 09:56 AM bom dia Tenho esta datagridview: http://img9.imageshack.us/img9/93/datagrid1.jpg Não sei como fazer o seguinte. Carregar numa qualquer célula do Cod_Produto, coluna 0, e obter o respetivo Nome, coluna 1. E vice versa, selecionar um qualquer Nome do Produto e obter o respetivo código. Já consegui carregar os códigos dos produtos e os nomes. Alguém me pode ajudar?
bioshock Posted May 28, 2013 at 10:35 AM Report #509382 Posted May 28, 2013 at 10:35 AM http://www.vbforums.com/showthread.php?656274-RESOLVED-Datagridview-Combobox-SelectedIndexChanged http://www.codeproject.com/Questions/157356/Perform-action-when-changing-selected-item-in-a-co Através do seguinte código consegues obter algumas propriedades da Combobox. Dim comboBoxCell As DataGridViewComboBoxCell = DataGridView1(1, 0)
csantos Posted May 28, 2013 at 11:10 AM Author Report #509388 Posted May 28, 2013 at 11:10 AM http://www.vbforums.com/showthread.php?656274-RESOLVED-Datagridview-Combobox-SelectedIndexChanged http://www.codeproject.com/Questions/157356/Perform-action-when-changing-selected-item-in-a-co Através do seguinte código consegues obter algumas propriedades da Combobox. Dim comboBoxCell As DataGridViewComboBoxCell = DataGridView1(1, 0) Isto está em C# ... n percebo muito ...
bioshock Posted May 28, 2013 at 11:25 AM Report #509389 Posted May 28, 2013 at 11:25 AM O 1º link está em VB.NET. Quanto ao 2º link, tens sempre bom remédio. 🙂 http://www.developerfusion.com/tools/convert/csharp-to-vb/
csantos Posted May 28, 2013 at 11:58 AM Author Report #509394 Posted May 28, 2013 at 11:58 AM (edited) O 1º link está em VB.NET. Quanto ao 2º link, tens sempre bom remédio. 🙂 http://www.developerfusion.com/tools/convert/csharp-to-vb/ Converti o código que me interessa mas dá-me erros "+=". O que devo aqui colocar? ' We will handle these events of the DataGridView dataGridView1.CellEndEdit += New DataGridViewCellEventHandler(AddressOf dataGridView1_CellEndEdit) dataGridView1.EditingControlShowing += New DataGridViewEditingControlShowingEventHandler(AddressOf dataGridView1_EditingControlShowing) End Sub Private Sub dataGridView1_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) If cbm IsNot Nothing Then ' Here we will remove the subscription for selected index changed cbm.SelectedIndexChanged -= New EventHandler(AddressOf cbm_SelectedIndexChanged) End If End Sub Private Sub dataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) ' Here try to add subscription for selected index changed event If TypeOf e.Control Is ComboBox Then cbm = DirectCast(e.Control, ComboBox) If cbm IsNot Nothing Then cbm.SelectedIndexChanged += New EventHandler(AddressOf cbm_SelectedIndexChanged) End If currentCell = Me.dataGridView1.CurrentCell End If End Sub Private Sub cbm_SelectedIndexChanged(sender As Object, e As EventArgs) ' Invoke method if the selection changed event occurs BeginInvoke(New MethodInvoker(AddressOf EndEdit)) End Sub Private Sub EndEdit() ' Change the content of appropriate cell when selected index changes If cbm IsNot Nothing Then Dim drv As DataRowView = TryCast(cbm.SelectedItem, DataRowView) If drv IsNot Nothing Then Me.dataGridView1(currentCell.ColumnIndex + 1, currentCell.RowIndex).Value = drv(2).ToString() Me.dataGridView1.EndEdit() End If End If End Sub End Class End Namespace Edited May 29, 2013 at 08:16 PM by thoga31 GeSHi
bioshock Posted May 28, 2013 at 12:14 PM Report #509398 Posted May 28, 2013 at 12:14 PM Isto: dataGridView1.EditingControlShowing += New DataGridViewEditingControlShowingEventHandler(AddressOf dataGridView1_EditingControlShowing) Passa a ser isto: AddHandler DataGridView1.EditingControlShowing, AddressOf editingControl Private Sub editingControl(sender As Object, e As DataGridViewEditingControlShowingEventArgs) ' Código End Sub
csantos Posted May 29, 2013 at 02:34 PM Author Report #509596 Posted May 29, 2013 at 02:34 PM Isto: dataGridView1.EditingControlShowing += New DataGridViewEditingControlShowingEventHandler(AddressOf dataGridView1_EditingControlShowing) Passa a ser isto: AddHandler DataGridView1.EditingControlShowing, AddressOf editingControl Private Sub editingControl(sender As Object, e As DataGridViewEditingControlShowingEventArgs) ' Código End Sub Tendo em conta o problema inicial que coloquei não estou mesmo a conseguir fazer isto 😕 Será que podes concretizar? Obrigado
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