Array
(
)

dataGridView - erro ao clicar no botão dropdown do combobox

Kokubotakeo
   - 07 jan 2008

O pessoal, No codigo de teste abaixo, quando clico no botão dropdown abre uma lista com dados filtrados, porem quando vou sair dessa lista clikando qualquer coisa dá um erro que não consegui descobrir. Alguem passou por algum problema similar e pode me ajudar?
takeo
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows.Forms
Imports System.Collections.Generic
Imports System.Drawing

Public Class Form1
Private territoriesBS As New BindingSource
Private regionBS As New BindingSource
Private m_cbxTerritories As DataGridViewComboBoxColumn

Private Sub form1_Load( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Me.Load

Dim strcon As String = ´data source=MAQTAKEO;initial catalog=northwind;integrated security=true´
Dim objcon As New SqlConnection(strcon)
Dim ds As New DataSet
Dim strCmd1 As String = ´SELECT * FROM territories´
Dim strCmd2 As String = ´SELECT * FROM region´

Dim adpTerritories As New SqlDataAdapter(strCmd1, objcon)
Dim adpRegion As New SqlDataAdapter(strCmd2, objcon)
objcon.Open()
adpRegion.Fill(ds, ´Region´)
adpTerritories.Fill(ds, ´territories´)

´ Setup BindingSource for filtered view.

Dim dv As DataView = New DataView(ds.Tables(´region´))
regionBS.DataSource = dv
objcon.Close()
dgv1.DataSource = regionBS

´ hide the auto-generated regionId column.
dgv1.Columns(´regionId´).Visible = False

Dim dv1 As DataView = New DataView(ds.Tables(´territories´))
territoriesBS = New BindingSource
territoriesBS.DataSource = dv1

´seta a posição da coluna no datagridview.
m_cbxTerritories = New DataGridViewComboBoxColumn
m_cbxTerritories.DisplayIndex = 2
m_cbxTerritories.HeaderText = ´territories´

´ This column is bound to the Products.CategoryID field.
m_cbxTerritories.DataPropertyName = ´regionId´

´ Esta coluna é linkado para o campo terriories description.
m_cbxTerritories.DataSource = territoriesBS
m_cbxTerritories.DisplayMember = ´TerritoryDescription´
m_cbxTerritories.ValueMember = ´RegionID´
´ Add the column.
dgv1.Columns.Add(m_cbxTerritories)
dgv1.AllowUserToAddRows = False
End Sub

Private Sub dgv1_CellBeginEdit( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) _
Handles dgv1.CellBeginEdit

If (e.ColumnIndex = m_cbxTerritories.Index) Then

´ Set the combobox cell datasource to the filtered BindingSource
Dim dgcb As DataGridViewComboBoxCell = CType(dgv1(e.ColumnIndex, e.RowIndex), DataGridViewComboBoxCell)
dgcb.DataSource = territoriesBS

´ Filter the BindingSource based upon the region selected
Me.territoriesBS.Filter = ´RegionID = ´ & dgv1((e.ColumnIndex - 2), e.RowIndex).Value.ToString

End If

End Sub

Private Sub dgv1_CellEndEdit( _
ByVal sender As Object, _
ByVal e As DataGridViewCellEventArgs) _
Handles dgv1.CellEndEdit
If (e.ColumnIndex = m_cbxTerritories.Index) Then
´ Reset combobox cell to the unfiltered BindingSource
Dim dgcb As DataGridViewComboBoxCell = CType(dgv1(e.ColumnIndex, e.RowIndex), DataGridViewComboBoxCell)
dgcb.DataSource = territoriesBS
´unfiltered()
Me.territoriesBS.RemoveFilter()
End If
End Sub

End Class