I have a combobox, where you should be able to add item (in this case colors/Hexcode selected from colordialog).
So lets say we have 3 items in that combobox:
Red
Green
Blue
and if you pick blue, the color blue should apper in a background color.
I can only get names to work, but i cant find out how to store the hex value data.
I need to save a name together with a hex value, but the value should be hidden. Save the Data along with the name.
You could create a DataTable with two columns, one for what to display, one as you call it hidden. Add rows to the DataTable, to show first set the DisplayMember to the column which will display and the ValueMember for the hidden value, set the DataSource of the control to the DataTable. On Selection Changed event of the control you can set the display item via the Text Property and the hidden value from SelectedValue
To read back data use a DataSet.ReadXml, point to the first Table in the DataSet to load the control. To save back to disk use DataTable.WriteXml.
Setup
Code:
Dim ds As New DataSet
ds.ReadXml(FileName)
ds.Tables(0).TableName = "SavedItems" ' must have a table name set
MyComboBox.DisplayMember = "DisplayColumn"
MyComboBox.ValueMember = "HiddenColumn"
MyComboBox.DataSource = ds.Tables(0)
Dim StringColor As [String] = "#FF00FF"
Dim Converter As New ColorConverter()
Dim MyColor As Color = DirectCast(Converter.ConvertFromString(StringColor), Color)
Console.WriteLine(MyColor.ToString)
Console.WriteLine(GetHexColor(MyColor))
Private Function GetHexColor(ByVal sender As System.Drawing.Color) As String
Return "#" & Hex(sender.R) & Hex(sender.G) & Hex(sender.B)
End Function