如何使用组合框显示datagridview1的内容 [英] How do I use a combo box to display datagridview1 content
问题描述
我有两个不同的桌子和一个组合框,
我试图编写代码,以便(例如)如果在组合框中选择甜食",则在dataGridView1中显示糖果表,而如果选择巧克力",则在dataGridView1中显示巧克力表.
到目前为止,我所拥有的所有代码都是....
I have two different tables and a combo box,
I trying to write the code so that (for example) if I select "sweets" in the combo box, the sweets table is displayed in the dataGridView1, and if I select "Chocolate" the chocolate table is displayed in the dataGridView1 instead.
So far all i have for code is ....
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedText == "Sweets")
{
DataGridView = SweetsInventoryDataSet;
}
有可能这样做吗?
我尝试过的事情:
Is it possible to do this?
What I have tried:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedText == "Sweets")
{
DataGridView = SweetsInventoryDataSet;
}
推荐答案
简单更正:
Simple correction:
DataGridView.DataSource = SweetsInventoryDataSet;
有关更多详细信息,请参见:
DataGridView.DataSource属性(System.Windows.表单) [如何:将数据绑定到Windows窗体DataGridView控件Microsoft文档 [
For further details, please see:
DataGridView.DataSource Property (System.Windows.Forms)[^]
How to: Bind Data to the Windows Forms DataGridView Control | Microsoft Docs[^]
这篇关于如何使用组合框显示datagridview1的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!