VB.net 级联组合框从 Access 连接到数据集 - 更改单位,&小数到分数

发布于 2024-12-07 18:11:46 字数 1988 浏览 0 评论 0原文

我有一个相当复杂的 ComboBox 场景,作为编程新手,我正在努力寻找最好的方法。

我有一个带有数据表的数据集,其中有多个数字数据列。数值数据由以美国标准单位给出的距离组成。我目前已经设置并运行了我的组合框,但我需要以两种方式扩展我目前拥有的内容。

  1. 我需要能够将显示的数据列中的小数转换为分数,有没有办法做到这一点并维护数据绑定?在本例中,它是数据源的显示成员...

  2. 我需要能够以不同的单位集显示我的下拉选项...我已经编写了单位转换类来帮助解决这个问题,但我不知道我是否也能以某种方式做到这一点并维护数据绑定?我也想转换显示成员上的单位...

    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.

  1. 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...

  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彡翼 2024-12-14 18:11:46

是的,您可以绘制小数而不影响数据绑定。您必须设置 DrawMode 属性并处理 DrawItemMeasureItem 事件。有关详细信息,请阅读 MSDN 文章;

Yes you can draw fractional without affecting DataBindings. You have to set DrawMode property and handle DrawItem and MeasureItem events. For more information read this MSDN article;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文