2012-11-09 39 views
0

您好顯示所選擇的組合框項目全部此分配在午夜VB.net Windows窗體(與Access數據庫連接)在一個文本框

是由於週日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 

結束類別

此處爲帶有COMBOBOX和TEXTBOX的ID如姓名,姓氏,名字等的表單代碼。當選擇組合項目時,需要顯示數據。再次ID正在顯示當我寫:IDTextBox.Text = SalesStaffComboBox.SelectedValue.ToString 但如果我不同爲其他文本框(LastName.Text = SalesStaffComboBox.SelectedValue.ToString _ ____ FirstName.Text = SalesStaffComboBox.SelectedValue.ToString)身份號碼顯示在他們身上。

公共類frmUpdateSalary 「所需要的類的實例 私人aCustomers作爲新客戶 私人aAppointments作爲新任命

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 
+0

我不確定你在問什麼。數據是否顯示在cboCustomer中? – ElenaDBA

回答

0

要選擇值形成一個組合框,列表框或下拉列表。

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

cmbBox.Items.removeAt(x) 

到所選擇的指數

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

沒有VS10在刪除要檢查的項目,如果這些都是正確的方法名稱或帽子,但其本質上它

+0

好吧,在你的對象客戶,你可以只挑釁領域ID和名稱?像comboSelectedItem.Name或comboSelectedItem.ID? – DWolf

0

你的組合框有兩個數據變量每個項目,值和顯示。
因此,對於每個客戶,您都有姓名和他的ID(您不指定它是最後的還是名字)。
如果在文本框你說:

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

你會得到相同的結果對每個文本框,因爲左邊是永遠不變的。 如果您的組合框的顯示值的姓氏和名字的組合,你可以有:

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

我沒有視覺工作室編寫的話,對不起,如果我有任何的小錯誤

你不解釋什麼是客戶,但我想象客戶的整個信息都在那裏。因此,您可以使用您已有的ID檢索數據。
如果您提供更多信息,我們可以提供幫助。

+0

您能否請您展示您填充aCustomers和文本框的代碼的代碼。我們需要了解您在客戶中的內容以及您發送給文本框的值 – Nianios

+0

如果您添加代碼來編輯您的問題會更好,因爲如同評論一樣,它無意義。您沒有顯示爲文本框的代碼。 我還沒有清楚在我的腦海中,你在填充aCustomers.Items。 但是無論如何你有所有的數據。只要你得到了身份證,你就可以找到名字和姓氏。這些信息存儲在哪裏? – Nianios

+0

HaBouF對不起,我真的是新來堆棧溢出和VB,所以我編輯這個問題希望與所有適當的代碼給你看,全部大寫不是我大喊抱歉。如果可以,請你幫助我。 –