本文介绍了在使用datasourse更新组合框时消除空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我是一个新手,我正在做一个小项目,其中有两个组合框,其中第一个是移动公司,第二个是移动模型我想更新模型列表,当第一个组合框选择从一个公司更改到另一个,我的意思是当选择诺基亚时它将显示所有模型列表,所以我使用了数据源数据绑定列来加载第二个组合框中的所有模型列表我已经做了这个 private void comboBox4_SelectedIndexChanged( object sender,EventArgs e) { comboBox3.Text = ; if ( samsung == comboBox4.SelectedItem.ToString()) { comboBox3.DataSource = table1BindingSource; comboBox3.ValueMember = samsung; comboBox3.DisplayMember = samsung; } if ( htc == comboBox4.SelectedItem.ToString()) { comboBox3.DataSource = table1BindingSource; comboBox3.ValueMember = htc; comboBox3.DisplayMember = htc; } } 表中有三列,nokia,htc和samsung,诺基亚模型列表包含12个单元格,htc包含当我在第一个组合框中选择htc时,6个单元被填充,然后在组合框中看到6行,但是也计算了6行并且在第二个组合框的列表中看作为空。如何在这里避免空值是我的问题解决方案 我不确定我是否正确理解了这个问题,但你是否在同一张表中有所有公司模型和单独的列。 如果是这种情况,我建议采用以下设计: 制造商-table - 制造商(生成,主键) - 名称 型号表 - modelid(生成,主键) - manufactrid(制造商的外键) - 名称 现在你可以在第一个组合中列出制造商框。根据选择,您可以使用以制造商标准作为标准过滤第二个组合框项目。 您可以在开始时获取所有模型并使用 DataView [ ^ ]仅列出每个制造商选择的适当模型。标准将使用 RowFilter [ ^ ] 附加: 数据示例: 制造商表 manufactrid name -------------- ---------- 1 Nokia 2三星 3 HTC 型号表 modelid manufacturerrid name ------- -------------- ---------- 1 1 C7 2 1 Lumia 900 3 1 Lumia 920 4 2 Galaxy S II 5 2 Galaxy S III 6 3欲望X 7 3 Windows Phone 8X 8 3 One S 现在,如果Sam sung被选中,rowfilter设置为定义 manufactrid = 2 因此只返回两行第二个组合框。相同的机制适用于所有制造商,但行数总是不同的(该制造商的模型数量)。 hi i am a newbie i am doing a small project in which there are two comboboxes in which first is of mobile company and second is of mobile model i want to update the list of model when the first combobox selection changes from one company to another, i mean when nokia is selected the it will show all the list of models so i have used datasource databinding of column for loading all the list of models in the second combobox i have made thisprivate void comboBox4_SelectedIndexChanged(object sender, EventArgs e) { comboBox3.Text = ""; if ("samsung" == comboBox4.SelectedItem.ToString()) { comboBox3.DataSource = table1BindingSource; comboBox3.ValueMember = "samsung"; comboBox3.DisplayMember = "samsung"; } if ("htc" == comboBox4.SelectedItem.ToString()) { comboBox3.DataSource = table1BindingSource; comboBox3.ValueMember = "htc"; comboBox3.DisplayMember = "htc"; } }there are three columns in the table, nokia, htc and samsung, nokia list of models contains 12 cells filled and htc contains 6 cells filled when i select the htc in the first combobox then 6 rows are seen in the combobox but 6 which are are also calculated and seen as null in the list of second combobox. how to avoid null values here is my problem 解决方案 I''m not sure if I understood the question correctly, but do you have all the companies in the same table with models and in separate columns.If that is the case, I suggest following kind of design:Manufacturer -table- manufacturerid (generated, primary key)- nameModel -table- modelid (generated, primary key)- manufacturerid (foreign key to manufacturer)- nameNow you could list the manufacturers in the first combo box. Based on the selection you could filter the second combobox items using the manufacturerid as the criteria.You could fetch all the models in the beginning and just use a DataView[^] to list only appropriate models per each manufacturer selection. The criteria would be defined using RowFilter[^]ADDITION:Example for the data:Manufacturer tablemanufacturerid name-------------- ----------1 Nokia2 Samsung3 HTCModel tablemodelid manufacturerid name------- -------------- ----------1 1 C72 1 Lumia 9003 1 Lumia 9204 2 Galaxy S II5 2 Galaxy S III6 3 Desire X7 3 Windows Phone 8X8 3 One SNow if Samsung is selected the rowfilter is set to definemanufacturerid = 2so only two rows would be returned for the second combobox. The same mechanism applies to all manufacturers but the amount of rows is always different (the amount of models for that manufacturer). 这篇关于在使用datasourse更新组合框时消除空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-11 19:00