所以我使用以下代码从WPF应用程序的列表中向ListView添加数据:
For Each elem As ModemDetails In MDList
MId = elem.ModemID
MRole = elem.Role
MComp = elem.COMPort
MBrate = elem.BaudRate
MDbits = elem.DataBits
MSbits = elem.StopBits
MPar = elem.Parity
MFcon = elem.FlowCtrl
MStat = elem.Status
lv_modemlist.Items.Add(New With {MId, MRole, MComp, MBrate, MDbits, MSbits, MPar, MFcon, MStat})
Next
现在数据进入列表正常并显示正常,但最后有一个随机生成的列,其中包含所有输入的数据:
我如何摆脱这个,因为我有另一个ListView使用类似的代码,不执行此操作?
这是我的XML:
<ListView x:Name="lv_modemlist" Margin="10,10,100,10" SelectionChanged="ListView_SelectionChanged_1" Grid.ColumnSpan="2">
<ListView.View>
<GridView>
<GridViewColumn Header="ID" Width="Auto" x:Name="IDCol" DisplayMemberBinding="{Binding MId}"/>
<GridViewColumn Header="Role" Width="Auto" x:Name="RoleCol" DisplayMemberBinding="{Binding MRole}"/>
<GridViewColumn Header="COM Port" Width="Auto" x:Name="COMPortCol" DisplayMemberBinding="{Binding MComp}"/>
<GridViewColumn Header="Baud Rate" Width="Auto" x:Name="BaudRateCol" DisplayMemberBinding="{Binding MBrate}"/>
<GridViewColumn Header="Data Bits" Width="Auto" x:Name="DataBitsCol" DisplayMemberBinding="{Binding MDbits}"/>
<GridViewColumn Header="Stop Bits" Width="Auto" x:Name="StopBitsCol" DisplayMemberBinding="{Binding MSbits}"/>
<GridViewColumn Header="Parity" Width="Auto" x:Name="ParityCol" DisplayMemberBinding="{Binding MPar}"/>
<GridViewColumn Header="Flow Control" Width="Auto" x:Name="FlowControlCol" DisplayMemberBinding="{Binding MFcon}"/>
<GridViewColumn Header="Status" Width="Auto" x:Name="StatusCol" DisplayMemberBinding="{Binding MStat}"/>
<GridViewColumn/>
</GridView>
</ListView.View>
</ListView>
干杯
答案 0 :(得分:0)
这似乎是一个愚蠢的建议,但您似乎已在GridViewColumn
中声明了10 GridView
。尝试评论最后一个:
<ListView x:Name="lv_modemlist" Margin="10,10,100,10" SelectionChanged="ListView_SelectionChanged_1" Grid.ColumnSpan="2">
<ListView.View>
<GridView>
<GridViewColumn Header="ID" Width="Auto" x:Name="IDCol" DisplayMemberBinding="{Binding MId}"/>
<GridViewColumn Header="Role" Width="Auto" x:Name="RoleCol" DisplayMemberBinding="{Binding MRole}"/>
<GridViewColumn Header="COM Port" Width="Auto" x:Name="COMPortCol" DisplayMemberBinding="{Binding MComp}"/>
<GridViewColumn Header="Baud Rate" Width="Auto" x:Name="BaudRateCol" DisplayMemberBinding="{Binding MBrate}"/>
<GridViewColumn Header="Data Bits" Width="Auto" x:Name="DataBitsCol" DisplayMemberBinding="{Binding MDbits}"/>
<GridViewColumn Header="Stop Bits" Width="Auto" x:Name="StopBitsCol" DisplayMemberBinding="{Binding MSbits}"/>
<GridViewColumn Header="Parity" Width="Auto" x:Name="ParityCol" DisplayMemberBinding="{Binding MPar}"/>
<GridViewColumn Header="Flow Control" Width="Auto" x:Name="FlowControlCol" DisplayMemberBinding="{Binding MFcon}"/>
<GridViewColumn Header="Status" Width="Auto" x:Name="StatusCol" DisplayMemberBinding="{Binding MStat}"/>
<!-- <GridViewColumn/> Try commenting this one out -->
</GridView>
</ListView.View>
</ListView>