0

こんにちはこの割り当ては11/12日曜日の深夜に予定されているため、これはやや緊急です。

コンボボックスアイテムを選択してから、下のテキストボックスに表示するデータを取得することで、助けが必要なものを添付しました

どうやってアプローチすればいいのかわからないので、コンボボックスをダブルクリックしました。これが、IDを表示するために始めたものです。私は他に何も試みていません。うまくいかなかったので、試したことをコメントアウトしました。

Public Class AppointmentsForm
    Private aAppointments As New Appointments

    'Instance of customers
    Private aCustomers As New Customers


    Private Sub AppointmentsForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'Combobox must always have a DataSource, Display Member, and Value Member
        'Load the ComboBox with customer name

        cboCustomer.DataSource = aCustomers.Items
        cboCustomer.DisplayMember = "CustName"
        cboCustomer.ValueMember = "CustId"
        cboCustomer.SelectedIndex = -1   'no items selected


        ' load the datagridview
        ApptDataGridView.DataSource = aAppointments.Items

        'do not show TypeID

        ApptDataGridView.Columns(1).Visible = False
        '.Columns(1) TypeID has index of 1 as it is Column 2 in the data sources

    End Sub

    Private Sub btnDelete_Click(sender As System.Object, e As System.EventArgs) Handles btnDelete.Click
        'make sure that a record is selected first
        If ApptDataGridView.SelectedRows.Count > 0 Then
            Dim apptid As Integer
            apptid = ApptDataGridView.SelectedRows(0).Cells(0).Value

            'Delete selected record by calling the delte function
            aAppointments.Delete(apptid)
        End If
    End Sub

    Private Sub btnEdit_Click(sender As System.Object, e As System.EventArgs) Handles btnEdit.Click
        'make sure row is selected get that row from the table ..... need to find by ID
        'This is a query which you will create in the class
        'Transfer information from that row to the form, display the form
        If ApptDataGridView.SelectedRows.Count > 0 Then
            modAppointmentsForm.ApptID = ApptDataGridView.SelectedRows(0).Cells(0).Value
            modAppointmentsForm.ShowDialog()
        End If
    End Sub
End Class

予定のクラスは次のとおりです。

パブリッククラスの予定

Public adapter As New CompanyDataSetTableAdapters.SalesStaffTableAdapter

'error variable
Public Shared Property LastError As String

Public ReadOnly Property Items() As DataTable
    Get
        Dim table As DataTable = adapter.GetData
        'sorted by Appointment id
        table.DefaultView.Sort = "ID"
        Return table
    End Get
End Property

'create a function to combine date and time
Public Shared Function CombinedDateTime(aDate As DateTime, aTime As DateTime) As DateTime
    'declare timespan variable
    Dim tsDate As New TimeSpan(aTime.Hour, aTime.Minute, 0)
    Return aDate.Add(tsDate)

End Function

これが顧客のためのクラスです:

パブリッククラスのお客様

'create a object variable (tableadapter)
'this will be used to creat instances of this class in the form

Private adapter As New CompanyDataSetTableAdapters.SalesStaffTableAdapter

'property to return a table using the GetData method
Public ReadOnly Property Items() As DataTable
    Get
        Dim table As DataTable = adapter.GetData
        table.DefaultView.Sort = "First_Name"
        Return table
    End Get
End Property

'create a function to filter the customers by custid
Public Function GetByCustomerId(custid As Short) As DataTable
    Dim table As DataTable = adapter.GetData 'entire table
    'filter to get desired row(s)
    table.DefaultView.RowFilter = " ID = " & custid
    Return table

End Function

エンドクラス

コンボボックスとテキストボックスのID、姓、名などのフォームのコードは次のとおりです。コンボボックスアイテムが選択されたときにデータを表示する必要があります。もう一度、書き込み時にIDが表示されます:IDTextBox.Text = SalesStaffComboBox.SelectedValue.ToStringただし、他のテキストボックスでも同じことを行う場合(LastName.Text = SalesStaffComboBox.SelectedValue.ToString _ ____ FirstName.Text = SalesStaffComboBox.SelectedValue.ToString )ID番号も同様に表示されます。

パブリッククラスfrmUpdateSalary'必要なクラスのインスタンスPrivateaCustomersAs New Customers Private aAppointments As New Appointments

Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
    Me.Close()
End Sub


Private Sub frmUpdateSalary_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    SalesStaffComboBox.DataSource = aCustomers.Items
    SalesStaffComboBox.DisplayMember = "First_Name"
     SalesStaffComboBox.ValueMember = "ID"


End Sub

Private Sub SalesStaffComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalesStaffComboBox.SelectedIndexChanged
    'fill the textboxes
    'Populate ID textbox with selected customer


    IDTextBox.Text = SalesStaffComboBox.SelectedValue.ToString



    End Sub
4

2 に答える 2

0

コンボボックスには、各項目に値と表示の 2 つのデータ変数があります。
したがって、顧客ごとに名前と ID があります (名前が姓か名かは指定しません)。
テキストボックスで次のように言う場合:

txtID.Text=cbo.SelectedValue.ToString
txtLastName.Text=cbo.SelectedValue.ToString
txtFirstName.Text=cbo.SelectedValue.ToString

左側は常に同じなので、各テキスト ボックスで同じ結果が得られます。コンボボックスの表示値が LastName と FirstName の組み合わせである場合、次のように指定できます。

txtID.Text=cbo.SelectedValue.ToString
txtName.Text=cbo.SelectedText.ToString

私はビジュアルスタジオなしで書いているので、軽微なエラーがあれば申し訳ありません

aCustomers とは何かを説明していませんが、顧客に関するすべての情報がそこにあると思います。したがって、すでに持っているIDでデータを取得できます。
より多くの情報を提供していただければ、私たちがお手伝いできます。

于 2012-11-09T20:38:45.943 に答える
0

コンボボックス、リストボックス、またはドロップダウンリストから値を選択するには。

 If cmbBox.selectedIndex <> -1 Then
     comboIndex = cmbBox.selectedIndex
 End Else

 cmbBox.Items.removeAt(x)

選択したインデックスのアイテムを削除するには

 If cmbBox.selectedIndex <> -1 Then
     comboItem= cmbBox.SelectedItem()

それらが正しいメソッド名またはキャップであるかどうかを確認するためのVS10なし

于 2012-11-09T18:21:03.037 に答える