Jump to content
csantos

DATAGRIDVIEW

Recommended Posts

csantos

bom dia

Tenho esta datagridview:

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?

Share this post


Link to post
Share on other sites
csantos

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 by thoga31
GeSHi

Share this post


Link to post
Share on other sites
bioshock

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

Share this post


Link to post
Share on other sites
csantos

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 :confused: Será que podes concretizar? Obrigado

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.