Answer the question
In order to leave comments, you need to log in
How to add a row to an already existing WPF column?
Good afternoon!
I have default columns in my DataGrid:
<DataGrid Name="dataGridView1" IsReadOnly="True" ColumnWidth="*" VerticalAlignment="Top"
CanUserResizeColumns="False" CanUserAddRows="False" CanUserDeleteRows="False"
CanUserReorderColumns="False" BorderThickness="0">
<DataGrid.Columns>
<DataGridTextColumn Header="Номер карты"></DataGridTextColumn>
<DataGridTextColumn Header="Симптомы"></DataGridTextColumn>
<DataGridTextColumn Header="Диагноз"></DataGridTextColumn>
<DataGridTextColumn Header="Лечение"></DataGridTextColumn>
<DataGridTextColumn Header="Дата приема"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
Answer the question
In order to leave comments, you need to log in
Hey!
Here is the simplest example of how you can programmatically add data to the DataGrid:
<DataGrid Name="dataGridView1" IsReadOnly="True" ColumnWidth="*" VerticalAlignment="Top"
CanUserResizeColumns="False" CanUserAddRows="False" CanUserDeleteRows="False"
CanUserReorderColumns="False" BorderThickness="0">
<DataGrid.Columns>
<DataGridTextColumn Header="Номер карты" Binding="{Binding Column1}"></DataGridTextColumn>
<DataGridTextColumn Header="Симптомы" Binding="{Binding Column2}"></DataGridTextColumn>
<DataGridTextColumn Header="Диагноз" Binding="{Binding Column3}"></DataGridTextColumn>
<DataGridTextColumn Header="Лечение" Binding="{Binding Column4}"></DataGridTextColumn>
<DataGridTextColumn Header="Дата приема" Binding="{Binding Column5}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
using System.Windows;
namespace WpfApp2
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
dataGridView1.Items.Add(new TestData { Column1 = "Col1,Row1", Column2 = "Col2,Row1", Column3 = "Col3,Row1", Column4 = "Col4,Row1", Column5 = "Col5,Row1" });
dataGridView1.Items.Add(new TestData { Column1 = "Col1,Row2", Column2 = "Col2,Row2", Column3 = "Col3,Row2", Column4 = "Col4,Row2", Column5 = "Col5,Row2" });
dataGridView1.Items.Add(new TestData { Column1 = "Col1,Row3", Column2 = "Col2,Row3", Column3 = "Col3,Row3", Column4 = "Col4,Row3", Column5 = "Col5,Row3" });
}
}
public class TestData
{
public string Column1 { get; set; }
public string Column2 { get; set; }
public string Column3 { get; set; }
public string Column4 { get; set; }
public string Column5 { get; set; }
}
}
What did you do wrong?Did you include jquery? Have you looked at the errors in the console? Didn't make an interactive example that we could look at?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question