使用基于名称vb.net的项填充数据网格

时间:2014-11-08 19:57:24

标签: vb.net datagridview

我有一个基本上得到隐藏组合框的索引的代码然后使用该索引来填充数据网格,但是我只想显示与lbl_test.text标签中的文本对应的项目。

Private Sub CBX_Doctors_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CBX_Doctors.SelectedIndexChanged
    lbl_test.Text = CBX_Doctors.SelectedItem.ToString
    CBX_hidden.SelectedItem = lbl_test.Text
    lbl_hidden.Text = CBX_hidden.SelectedIndex.ToString

    Dim app = Convert.ToInt32(lbl_hidden.Text)
    DGV_1.DataSource = AppointmentList
End Sub



Public Class Appointment

   Property AppointmentID As String
   Property AppointmentDate As String
   Property Time As String
   Property AppointmentLength As Integer
   Property DoctorName As String
   Property PatientName As String
   Property Reason As String

End Class

这是负责保存到xml文件的代码的请求部分:

 'save to the xml
    Dim objStreamWriter4 As New StreamWriter("..\..\..\Appointments.xml")
    Dim a As New XmlSerializer(AppointmentList.GetType)
    a.Serialize(objStreamWriter4, AppointmentList)
    objStreamWriter4.Close()

1 个答案:

答案 0 :(得分:-1)

听起来你想根据其中一个等于lbl_test.Text的字段来过滤返回列表 - 如果这是正确的,那么你可以这样做:

Private Sub CBX_Doctors_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CBX_Doctors.SelectedIndexChanged
   Dim doctorName = CBX_Doctors.SelectedItem.ToString
   CBX_hidden.SelectedItem = doctorName
   lbl_hidden.Text = CBX_hidden.SelectedIndex.ToString
   DGV_1.DataSource = AppointmentList.Where(Function(apt) apt.DoctorName = doctorName)
End Sub