VB.net 级联组合框从 Access 连接到数据集 - 更改单位,&小数到分数
我有一个相当复杂的 ComboBox 场景,作为编程新手,我正在努力寻找最好的方法。
我有一个带有数据表的数据集,其中有多个数字数据列。数值数据由以美国标准单位给出的距离组成。我目前已经设置并运行了我的组合框,但我需要以两种方式扩展我目前拥有的内容。
我需要能够将显示的数据列中的小数转换为分数,有没有办法做到这一点并维护数据绑定?在本例中,它是数据源的显示成员...
我需要能够以不同的单位集显示我的下拉选项...我已经编写了单位转换类来帮助解决这个问题,但我不知道我是否也能以某种方式做到这一点并维护数据绑定?我也想转换显示成员上的单位...
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) 处理 ComboBox1.SelectionChangeComfilled 选择案例 ComboBox1.SelectedItem 案例“轮胎1” 使用组合框2 .DataSource = Tire1BindingSource .ValueMember =“OD” .DisplayMember = "OD" 结束于 案例“轮胎2” 使用组合框2 .DataSource = Tire2BindingSource .ValueMember =“OD” .DisplayMember = "OD" 结束于 案例“轮胎3” 使用组合框2 .DataSource = Tire3BindingSource .ValueMember =“OD” .DisplayMember = "OD" 结束于 案例“轮毂盖” ComboBox3.DataSource = 无 使用组合框2 .DataSource = HubcapBindingSource .ValueMember =“ID” .DisplayMember = "ID" 结束于 结束选择 结束子 Private Sub ComboBox2_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) 处理 ComboBox2.SelectionChangeComfilled 选择案例 ComboBox1.SelectedItem 案例“轮胎1” 与组合框3 .DataSource = Tire1BindingSource .ValueMember =“ID” .DisplayMember = "权重" 结束于 案例“轮胎2” 与组合框3 .DataSource = Tire2BindingSource .ValueMember =“ID” .DisplayMember = "权重" 结束于 案例“轮胎3” 与组合框3 .DataSource = Tire3BindingSource .ValueMember =“ID” .DisplayMember = "权重" 结束于 案例“轮毂盖” ComboBox3.DataSource = 无 使用组合框2 .DataSource = HubCapBindingSource .ValueMember =“ID” .DisplayMember = "ID" 结束于 结束选择
在处理显示分数和单位等问题时使用组合框的最佳方法是什么...
I've got a fairly complex ComboBox scenario, and being new to programming I'm struggling with what the best approach to take is.
I have a DataSet with a DataTable that has several numeric columns of Data. The numeric data is composed of distances given in U.S. Standard units. I currently have my ComboBoxes set up and working, but I need to expand on what I currently have in two ways.
I need to be able to convert the Decimal numbers in my data column being displayed to Fractions, is there a way to do this and maintain databinding? In this case its the Display Member of the data source...
I need to be able to display my drop down options in different sets of units... I've written Unit Conversion classes to help take care of this, but I don't know if I can somehow do this as well and maintain databinding? I'd like to convert the units on the display members as well...
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted Select Case ComboBox1.SelectedItem Case "Tire1" With ComboBox2 .DataSource = Tire1BindingSource .ValueMember = "OD" .DisplayMember = "OD" End With Case "Tire2" With ComboBox2 .DataSource = Tire2BindingSource .ValueMember = "OD" .DisplayMember = "OD" End With Case "Tire3" With ComboBox2 .DataSource = Tire3BindingSource .ValueMember = "OD" .DisplayMember = "OD" End With Case "HubCap" ComboBox3.DataSource = Nothing With ComboBox2 .DataSource = HubcapBindingSource .ValueMember = "ID" .DisplayMember = "ID" End With End Select End Sub Private Sub ComboBox2_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox2.SelectionChangeCommitted Select Case ComboBox1.SelectedItem Case "Tire1" With ComboBox3 .DataSource = Tire1BindingSource .ValueMember = "ID" .DisplayMember = "Weight" End With Case "Tire2" With ComboBox3 .DataSource = Tire2BindingSource .ValueMember = "ID" .DisplayMember = "Weight" End With Case "Tire3" With ComboBox3 .DataSource = Tire3BindingSource .ValueMember = "ID" .DisplayMember = "Weight" End With Case "HubCap" ComboBox3.DataSource = Nothing With ComboBox2 .DataSource = HubCapBindingSource .ValueMember = "ID" .DisplayMember = "ID" End With End Select
What is the best approach for using ComboBoxes when dealing with issues such as displaying fractions and units...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以绘制小数而不影响数据绑定。您必须设置 DrawMode 属性并处理
DrawItem
和MeasureItem
事件。有关详细信息,请阅读此 MSDN 文章;Yes you can draw fractional without affecting DataBindings. You have to set DrawMode property and handle
DrawItem
andMeasureItem
events. For more information read this MSDN article;