当我点击添加按钮时,我想将combobox
项和测试框文本添加到datagrid
或ListView
下方,然后我点击save button
我要save them in my database
1}}表?
如何添加值并保存?示例界面图像如下所示:
答案 0 :(得分:1)
这是一个复杂的问题,我想没有一个正确的答案。我会建议你start with this lab。 另外there你可以找到关于数据访问的一个很好的快速启动指令。
答案 1 :(得分:1)
当我点击添加按钮时,我想将组合框项目和测试框文本添加到datagrid或ListView下面,
你可以使用这个示例代码:
C#
public ObservableCollection<Model> ModelListe { get; set; }
public MainWindow()
{
InitializeComponent();
comboBox1.Items.Add("Test1");
comboBox1.Items.Add("Test2");
comboBox1.Items.Add("Test3");
comboBox1.Items.Add("Test4");
comboBox1.Items.Add("Test5");
ModelListe = new ObservableCollection<Model>();
DataContext = this;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
if (textBox1.Text != "")
{
if (comboBox1.SelectedItem != null)
{
Model model = new Model();
model.Component = comboBox1.SelectedItem.ToString();
model.Question = textBox1.Text;
ModelListe.Add(model);
}
}
}
public class Model
{
public string Component { get; set; }
public string Question { get; set; }
}
XAML
<ComboBox Height="29" HorizontalAlignment="Left" Margin="12,14,0,0" Name="comboBox1" VerticalAlignment="Top" Width="199" />
<TextBox Height="29" HorizontalAlignment="Left" Margin="12,53,0,0" Name="textBox1" VerticalAlignment="Top" Width="199" />
<DataGrid ItemsSource="{Binding ModelListe}" AutoGenerateColumns="False" Height="97" HorizontalAlignment="Left" Margin="12,92,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="199" >
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Component}" CanUserReorder="False" Header="Component" Width="100" />
<DataGridTextColumn Binding="{Binding Question}" CanUserReorder="False" Header="Question" Width="100" />
</DataGrid.Columns>
</DataGrid>
<Button Content="Add" Height="29" HorizontalAlignment="Left" Margin="214,53,0,0" Name="button1" VerticalAlignment="Top" Width="41" Click="button1_Click" />
我希望,我可以帮助你。