更改数据网格中显示的内容

时间:2014-11-09 14:36:35

标签: xml vb.net datagrid combobox

我正在尝试制作一个程序,一旦组合框发生了变化,它就会获取该文本属性并在xml中找到匹配的名称,然后它只显示带有这些名称的条目到数据网格。 请参阅图片以供参考:http://i.imgur.com/UCvGw0j.png看看它如何显示Doogie?那是因为目前我已将它设置为显示整个AppointmentList但它应该做的只是显示医生选择。

现在我的当前代码如下所示:

 Private Sub CBX_Doctors_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CBX_Doctors.SelectedIndexChanged

    Dim doctorName As String = CBX_Doctors.SelectedItem.ToString

    DGV_1.DataSource = AppointmentList.Where(Function(apt) apt.DoctorName = doctorName)

 End Sub

但是这只显示了一个空白的数据网格,在调试时我得到了这个: http://i.imgur.com/njTtWyp.png

所以它找到匹配,但由于某种原因,数据网格没有给出任何显示...

约会列表在控制器模块中声明:

Module Controller

 Public PatientList As New List(Of Patient)
 Public DoctorList As New List(Of Doctor)
 Public AppointmentList As New List(Of Appointment)

End Module

和预约看起来像这样:

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太大而无法在此发布,因此我只添加了一小部分内容:

  <ArrayOfAppointment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
     <Appointment>
      <AppointmentID>700864b004e84b139119227d88388dcb</AppointmentID>
      <AppointmentDate>10/30/2014</AppointmentDate>
      <Time>7:20 AM</Time>
      <AppointmentLength>15</AppointmentLength>
      <DoctorName>Doogie Howser</DoctorName>
      <PatientName>Harry Potter</PatientName>
      <Reason>The patient has severe scared tissue at forehead, wishes to have it removed.       </Reason>
     </Appointment>
   </ArrayOfAppointment>

我像这样序列化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)

尝试更改

DGV_1.DataSource = AppointmentList.Where(Function(apt) apt.DoctorName = doctorName)

DGV_1.DataSource = AppointmentList.Where(Function(apt) apt.DoctorName = doctorName).ToList()