0

フォームにデータグリッドビューとコンボボックスがあります。datagridview の行間を移動したいのですが、コンボボックスはデータセット datagridview の列の 1 つの値と同期する必要があります。コンボボックスには、Rational (1) と Irrational (2) という 2 つの可能な値のリストがあります。データセットの列「TYPE」は、以前のタイプを参照します。以下はコードですが、目的の結果が得られません。なにが問題ですか?

ありがとう、デイビス

Public Class Form1
Private BdgSource As BindingSource = New BindingSource
Private StrCon As String = "Server=LOCALHOST:50000;Database=SAMPLE;UID=USERX;PWD=YYY;Connect Timeout=30"
Private Dts As DataSet = New DataSet

Private Class TypeAnimal
    Private _Type As Integer = 0
    Private _Desc As String = ""

    Property Type As Integer
        Set(ByVal value As Integer)
            _Type = value
        End Set
        Get
            Return _Type
        End Get
    End Property

    Property Description As String
        Set(ByVal value As String)
            _Desc = value
        End Set
        Get
            Return _Desc
        End Get
    End Property

    Public Sub New(ByVal Type As Integer, ByVal Description As String)
        _Type = Type
        _Desc = Description
    End Sub

End Class

Private Sub UpdateDatagridView()
    Dim con As DB2Connection = New DB2Connection(StrCon)
    'Dim trans As DB2Transaction
    Dim cmd As DB2Command = New DB2Command
    Dim adp As DB2DataAdapter = New DB2DataAdapter

    con.Open()
    cmd.Transaction = con.BeginTransaction
    cmd.Connection = con
    cmd.CommandText = "SELECT ANIMAL, TYPE FROM TESTE"
    'cmd.ExecuteNonQuery()
    adp.SelectCommand = cmd
    adp.Fill(Dts, "TABLE1")

    BdgSource.DataSource = Dts.Tables(0)

    DataGridView1.DataSource = BdgSource.DataSource

End Sub

Private Sub FillCombobox()
    Dim lista As List(Of TypeAnimal) = New List(Of TypeAnimal)

    lista.Add(New TypeAnimal(1, "Rational"))
    lista.Add(New TypeAnimal(2, "Irrational"))

    ComboBox1.DataSource = lista
    ComboBox1.DisplayMember = "Description"
    ComboBox1.ValueMember = "Type"

End Sub

Private Sub BindComponents()
    Dim bd As Binding = New Binding("SelectedValue", BdgSource, "TYPE")
    ComboBox1.DataBindings.Add(bd)
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    UpdateDatagridView()
    FillCombobox()
    BindComponents()
End Sub
End Class
4

1 に答える 1

1

あなたのコードは、データグリッドビューとコンボボックスを埋めるためにうまく機能するはずです

コードで他に何をしたいですか?

(望ましい結果) とはどういう意味ですか?

datagridview で選択した行を変更するときにコンボボックスの値を変更するのですか?

もしそうなら 。. . 次に、SelectedIndexChangedを処理する必要があります

于 2013-06-10T07:32:18.757 に答える