【问题标题】:Change what is shown in a datagrid更改数据网格中显示的内容
【发布时间】:2015-01-05 21:38:55
【问题描述】:

我正在尝试制作一个程序,一旦组合框发生更改,它就会获取该组合框的文本属性并在 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 太大,无法在这里发布,所以我只添加了一个 sn-p:

  <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()

【问题讨论】:

    标签: xml vb.net datagrid combobox


    【解决方案1】:

    尝试改变

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

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

    【讨论】:

    • 谢谢,这解决了问题!
    猜你喜欢
    • 2016-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多