我正在开发一个餐厅应用程序,其中将放置新订单。 Itemtype将在组合框中。基于组合框值的选择,结果应显示在DataGridView中。例如,如果我在组合框中选择“Biryani”项目,则应在DataGridView中显示所有Biryani类型项目。基于组合框选定值未显示Gridview数据
0
A
回答
0
正如我可以读,你在谈论DAtaGridView和组合框,你必须使用Windows窗体。所以你可以做的是调用ComboBox的SelectedIndexChanged事件,然后你可以绑定DataGridView。例如
private void ComboBox1_SelectedIndexChanged(object sender, System.EventArgs e) { ComboBox combo = sender as ComboBox; if(combo.SelectedIndex >=0) { int itemId=Convert.ToInt32(combo.SelectedValue); datagridview1.DataSource = somFunction(itemId); } }
0
据我理解你的问题,你也许可以做到这一点:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
public class Selection {
public enum eType { None, Indian, Chinese, Italian, British };
public eType Type { get; private set; }
public string Name { get; private set; }
public Selection(eType xType, string xName) {
Type = xType;
Name = xName;
} //
} // class
private List<Selection> _AllMeals = new List<Selection>();
public Form1() {
InitializeComponent();
comboBox1.DataSource = Enum.GetValues(typeof(Selection.eType)).Cast<Selection.eType>();
comboBox1.SelectedItem = Selection.eType.None;
Selection s1 = new Selection(Selection.eType.Chinese, "tasty Wan Tan soup");
Selection s2 = new Selection(Selection.eType.Chinese, "yummy Spring Rolls");
Selection s3 = new Selection(Selection.eType.Indian, "extreme spicy");
Selection s4 = new Selection(Selection.eType.Indian, "deadly spicy");
Selection s5 = new Selection(Selection.eType.Italian, "great Tortellini");
Selection s6 = new Selection(Selection.eType.Italian, "large Pizza");
Selection s7 = new Selection(Selection.eType.British, "fatty Fish and Chips");
_AllMeals.AddRange(new Selection[] { s1, s2, s3, s4, s5, s6, s7 });
dataGridView1.DataSource = _AllMeals;
} //
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {
object o = comboBox1.SelectedItem;
Selection.eType lFilter = (Selection.eType)o;
var lOptions = (from x in _AllMeals
where x.Type == lFilter
select x).ToArray();
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = lOptions;
dataGridView1.Invalidate();
} //
} // class
} // namespace
访问我的博客www.ohta.de
+0
这是一个ASP.NET WebForms相关问题,您的答案适用于Windows DataGrid –
相关问题
- 1. 基于组合框选择显示特定数据
- 2. 数据绑定的WPF组合框不显示选定的值
- 3. 组合框不显示选定的值
- 4. WPF组合框显示选定的值?
- 5. VB6基于数据库数据选择组合框文本值
- 6. 组合框数据未显示在即
- 7. 以组合框的形式显示组合框的选定值
- 8. wpf组合框的选定值不显示在组合框上
- 9. AngularJS - 基于选择值显示数据
- 10. Extjs5:组合框未显示选定的值
- 11. 基于组合框选择在文本框上显示阀门
- 12. 基于Textbox.Text选择组合框值
- 13. 基于GridView数据显示新表格
- 14. WPF组合框SelectedItem未显示其值
- 15. 基于复选框的值显示div
- 16. Silverlight 4的MVVM组合框的数据绑定未显示
- 17. 基于组合框选择从数据库中检索数据
- 18. 基于数据表值在gridview中设置复选框
- 19. 如何显示基于组合框选择在ExtJS的
- 20. Flex - 显示/隐藏基于关闭选择的组合框
- 21. 基于组合框项目选择在WPF中显示图像
- 22. 显示基于组合框选择的结果
- 23. DataGridView的组合框柱不显示选择组合框的值
- 24. 如何基于GridView中数据库的coulmn值显示图像?
- 25. 如何显示文本框C#中的组合框选定值?
- 26. 基于GridView之外的复选框过滤GridView数据?
- 27. Siliverlight数据绑定组合框不显示初始化值
- 28. IE11未显示组合/选择框的标题值
- 29. 基于复选框获取数组值
- 30. VBA,基于复选框值的数组?
请添加你的代码有问题。 – Adil
使用AutoPostBack = True在你的组合中。所以当事件index_change发生时,从数据库中选择结果,或者你可以通过ajax来完成。但是强制提供你已经尝试过的东西。 –