【发布时间】:2014-11-11 03:23:57
【问题描述】:
我被困住了,需要一些帮助。我花了一整天的时间试图解决这个问题。我已经阅读了很多应该如何做到这一点的例子,看起来我做得正确,但显然我错过了一些东西。我有一个带有一个按钮和一个数据网格的空白表单。当我单击按钮时,我想将点列表加载到 datagrid 控件中。必须加载数据,因为我在网格中看到三个空白行(没有标题),但没有数据。请帮忙!谢谢!
Class MainWindow
Class Point
Public Inc As String
Public AZ As String
Public MD As String
Public TD As String
End Class
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim mySurvey As New List(Of Point)
Dim myPoint1 As New Point
Dim myPoint2 As New Point
myPoint1.AZ = "1"
myPoint1.Inc = "2"
myPoint1.MD = "100"
myPoint1.TD = "98"
myPoint2.AZ = "10"
myPoint2.Inc = "20"
myPoint2.MD = "1000"
Point2.TD = "980"
mySurvey.Add(myPoint1)
mySurvey.Add(myPoint2)
dgSurvey.ItemsSource = mySurvey
End Sub
结束类
XAML
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Button" HorizontalAlignment="Left" Height="28" Margin="45,30,0,0" VerticalAlignment="Top" Width="57" Click="Button_Click"/>
<DataGrid x:Name="dgSurvey" HorizontalAlignment="Left" Margin="45,78,0,0" VerticalAlignment="Top" Height="172" Width="275"/>
</Grid>
【问题讨论】:
-
你能分享你的 xaml 吗?
-
刚刚将其添加到问题中。谢谢尼特
-
我认为你应该在
Point类中定义属性,而不是公共字段,这样才能正常工作。 -
icebat 你太棒了。非常感谢。问题解决了。发布为答案,我会选择它。
标签: wpf vb.net datagrid wpfdatagrid