当我想使用C#填充WPF DataGrid时遇到问题。在XAML中,我创建了列,并用包含数据的字符串列表将列绑定。这是我的代码,您能告诉我我做错了什么吗,因为已经两天了,我被卡住了?
<DataGrid x:Name="ListeFiches" HorizontalAlignment="Left" Height="278" Margin="10,126,0,0" VerticalAlignment="Top" Width="612" SelectionChanged="ListeFiches_SelectionChanged" AutoGenerateColumns="False" Loaded="Window_Loaded">
<DataGrid.Columns>
<DataGridTextColumn Header="Progiciel" x:Name="prog" />
<DataGridTextColumn Header="nbfiche" x:Name="nbfiche" />
<DataGridTextColumn Header="etb" x:Name="etb" />
<DataGridTextColumn Header="Demandeur" x:Name="Demand" />
<DataGridTextColumn Header="Correcteur" x:Name="correc" />
<DataGridTextColumn Header="PRGM" x:Name="PRGM" />
<DataGridTextColumn Header="APP" x:Name="APP" />
<DataGridTextColumn Header="MOD" x:Name="MOD" />
<DataGridTextColumn Header="OPT" x:Name="OPT" />
</DataGrid.Columns>
</DataGrid>
我的代码:
try
{
conn.Open();
if (conn != null)
{
// MessageBox.Show("connexion établie");
string qry = "SELECT * FROM DIITOOL.FICENT where MTPRO = 'G12' or MTPRO='URG' ";
iDB2Command comm = conn.CreateCommand();
comm.CommandText = qry;
iDB2DataReader reader = comm.ExecuteReader();
while (reader.Read())
{
data.Add(reader[0].ToString() + reader[1].ToString() + reader[2].ToString()
+ reader[3].ToString() + reader[4].ToString() + reader[5].ToString() + reader[7].ToString());
}
ListeFiches.Items.Add(data);
reader.Close();
comm.Dispose();
}
}
catch (Exception ex)
{
MessageBox.Show("Error : " + ex.ToString());
}
和空白行是这样的 enter image description here