Results 1 to 11 of 11

Thread: Match the values of 3 numericUpDown's

  1. #1

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Match the values of 3 numericUpDown's

    Hi All,

    I'm using VB 2008 and I have a combobox filled with all ARGB knowncolors.
    When I do a selection in the combobox, the numericupdown's showing me the exact value.

    What I want is, when I select some values in the numericupdown's and there's a match with the corresponding color in the combobox. The combobox will show the colors name.

    How can I do that?

    Thanks in advance,

    sparrow1
    Last edited by sparrow1; Jul 7th, 2008 at 10:55 AM.
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  2. #2
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: Match the values of 3 numericUpDown's

    will this be a usefull?

    Code to fill combobox (cmb1) with color name
    Code:
    Dim dtColor As DataTable = New DataTable("Color")
            dtColor.Columns.Add(New DataColumn("Name"))
            dtColor.Columns.Add(New DataColumn("RGBValue"))
    
            Dim c As Color = Color.Blue
            Dim i As Integer
            For i = 0 To 165
                c = Color.FromKnownColor(i)
                If Not c.IsSystemColor Then
                    Dim drNewColor As DataRow
                    drNewColor = dtColor.NewRow
                    drNewColor.Item("Name") = c.ToKnownColor.ToString
                    drNewColor.Item("RGBValue") = c.R.ToString & "," & c.G.ToString & "," & c.B.ToString
                    dtColor.Rows.Add(drNewColor)
                End If
            Next
    
            cmb1.DataSource = dtColor
            cmb1.DisplayMember = "Name"
            cmb1.ValueMember = "RGBValue"
    let's say NumericUpDown control are R,G,B respectively...
    so to display select the color in cmb1 you can use...



    Code:
    cmb1.SelectedValue = R.Value.ToString & "," & G.Value.ToString & "," & B.Value.ToString
    __________________
    Rate the posts that helped you

  3. #3

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Match the values of 3 numericUpDown's

    Hi,

    It's not working.

    I can already show the proper value in the numericUpDown, but what I want is, if you select the R.value = 255 then the combobox should give the name: RED.

    Is that possible and if so, how should I do that?

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  4. #4
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: Match the values of 3 numericUpDown's

    if you have use above method to pupulate your combobox then setting

    Code:
    cmb1.SelectedValue = "255,0,0"
    will select the Red color in comobox.
    __________________
    Rate the posts that helped you

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Match the values of 3 numericUpDown's

    sparrow, do you have three combo boxes?
    cmb1 = r value
    cmb2 = g value
    cmb3 = b value
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  6. #6
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Match the values of 3 numericUpDown's

    Quote Originally Posted by riteshjain1982
    will this be a usefull?

    Code to fill combobox (cmb1) with color name
    Code:
    Dim dtColor As DataTable = New DataTable("Color")
            dtColor.Columns.Add(New DataColumn("Name"))
            dtColor.Columns.Add(New DataColumn("RGBValue"))
    
            Dim c As Color = Color.Blue
            Dim i As Integer
            For i = 0 To 165
                c = Color.FromKnownColor(i)
                If Not c.IsSystemColor Then
                    Dim drNewColor As DataRow
                    drNewColor = dtColor.NewRow
                    drNewColor.Item("Name") = c.ToKnownColor.ToString
                    drNewColor.Item("RGBValue") = c.R.ToString & "," & c.G.ToString & "," & c.B.ToString
                    dtColor.Rows.Add(drNewColor)
                End If
            Next
    
            cmb1.DataSource = dtColor
            cmb1.DisplayMember = "Name"
            cmb1.ValueMember = "RGBValue"
    let's say NumericUpDown control are R,G,B respectively...
    so to display select the color in cmb1 you can use...



    Code:
    cmb1.SelectedValue = R.Value.ToString & "," & G.Value.ToString & "," & B.Value.ToString
    This code is indeed not working correctly. The first item on the list in the ComboBox is '0' followed by what seems to be all the other colors. As soon as you change a value in any of the NUD's the ComboBox loses it's selected index.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  7. #7
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: Match the values of 3 numericUpDown's

    Quote Originally Posted by JuggaloBrotha
    This code is indeed not working correctly. The first item on the list in the ComboBox is '0' followed by what seems to be all the other colors.
    You can change For i = 0 To 165 as per your need.


    Quote Originally Posted by JuggaloBrotha
    As soon as you change a value in any of the NUD's the ComboBox loses it's selected index.
    make sure combination of RGB NUD has any knownColor Name.
    __________________
    Rate the posts that helped you

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Match the values of 3 numericUpDown's

    Code:
        Private Sub RGBnudValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles Rnud.ValueChanged, Gnud.ValueChanged, Bnud.ValueChanged
            Dim aColor = Color.FromArgb(Convert.ToInt32(Rnud.Value), Convert.ToInt32(Gnud.Value), Convert.ToInt32(Bnud.Value))
            Dim conv As ColorConverter = New ColorConverter()
            Debug.WriteLine(conv.ConvertFromString(aColor.ToArgb.ToString))
        End Sub
    conv.ConvertFromString(aColor.ToArgb.ToString is a color name.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Match the values of 3 numericUpDown's

    Quote Originally Posted by dbasnett
    sparrow, do you have three combo boxes?
    cmb1 = r value
    cmb2 = g value
    cmb3 = b value
    Hi,

    I have 1 combobox and 3 numericUpDown's. and I'm populating the combobox in the formload like this:

    vb.net Code:
    1. Dim color() As String
    2.         Kleur = System.Enum.GetNames(GetType(KnownColor))
    3.         ComboBox1.Items.AddRange(color)

    This is how I show the values in the numericupdown's after selection in the combobox selectedindexchanged:

    vb.net Code:
    1. Dim ColorEnum As Object
    2.         ColorEnum = System.Enum.Parse(GetType(KnownColor), ComboBox1.Text)
    3.  
    4.         Dim selectedColor As KnownColor
    5.         selectedColor = CType(ColorEnum, KnownColor)
    6.  
    7.         Dim color As Color = System.Drawing.Color.FromKnownColor(selectedColor)
    8.         ComboBox1.BackColor = System.Drawing.Color.FromKnownColor(selectedColor)
    9.         Label6.BackColor = color
    10.        
    11.  
    12.         nmr1.Value = kleur.R
    13.         nmr2.Value = kleur.G
    14.         nmr3.Value = kleur.B

    How can I do a selection value in the numericupdown's and if there's a match the combobox will shown the name of the color.

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  10. #10
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Match the values of 3 numericUpDown's

    i posted code with 3 numeric up/downs that returned a color name based on the value of the numeric up/downs, if there is one.
    Last edited by dbasnett; Jul 9th, 2008 at 10:02 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  11. #11
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Match the values of 3 numericUpDown's

    Quote Originally Posted by sparrow1
    Hi,

    I have 1 combobox and 3 numericUpDown's. and I'm populating the combobox in the formload like this:

    vb.net Code:
    1. Dim color() As String
    2.         Kleur = System.Enum.GetNames(GetType(KnownColor))
    3.         ComboBox1.Items.AddRange(color)

    This is how I show the values in the numericupdown's after selection in the combobox selectedindexchanged:

    vb.net Code:
    1. Dim ColorEnum As Object
    2.         ColorEnum = System.Enum.Parse(GetType(KnownColor), ComboBox1.Text)
    3.  
    4.         Dim selectedColor As KnownColor
    5.         selectedColor = CType(ColorEnum, KnownColor)
    6.  
    7.         Dim color As Color = System.Drawing.Color.FromKnownColor(selectedColor)
    8.         ComboBox1.BackColor = System.Drawing.Color.FromKnownColor(selectedColor)
    9.         Label6.BackColor = color
    10.        
    11.  
    12.         nmr1.Value = kleur.R
    13.         nmr2.Value = kleur.G
    14.         nmr3.Value = kleur.B

    How can I do a selection value in the numericupdown's and if there's a match the combobox will shown the name of the color.

    Wkr,

    sparrow1
    dbasnett's code works but not every color combination has a name in that color enumeration so most of your combinations will result in a selected index of -1.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width