如何将原始数据添加到我的数据网格
本文关键字:我的 数据 数据网 网格 添加 原始数据 | 更新日期: 2023-09-27 18:36:48
我需要在我的代码中添加原始数据。但我只能添加列。如何添加原始?
<Page x:Class="HHT.Table"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:HHT"
mc:Ignorable="d"
Title="Table" Height="520" Width="985">
<Grid Margin="0,0,-505,-120" HorizontalAlignment="Left" Width="805" Height="420" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<DataGrid x:Name="dataGrid" SelectionChanged="dataGrid_SelectionChanged" Margin="0,0,70,30" HorizontalAlignment="Right" Width="725">
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding XPath=@ID}"></DataGridTextColumn>
<DataGridTextColumn Header="Last Name"></DataGridTextColumn>
<DataGridTextColumn Header="First Name"></DataGridTextColumn>
<DataGridTextColumn Header="Birthday"></DataGridTextColumn>
<DataGridTextColumn Header="Phone Number"> </DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Page>
string[] row = new string[] { "1", "Product 1", "1000" };
dataGridView1.Rows.Add(row);
row = new string[] { "2", "Product 2", "2000" };
dataGridView1.Rows.Add(row);
row = new string[] { "3", "Product 3", "3000" };
dataGridView1.Rows.Add(row);
row = new string[] { "4", "Product 4", "4000" };
dataGridView1.Rows.Add(row);
源: http://csharp.net-informations.com/datagridview/csharp-datagridview-add-column.htm