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)
Write back to disk
Code:
DirectCast(MyComboBox.DataSource, DataTable).WriteXml(FileName)
How you might create the intial DataTable
Code:
Dim table As New DataTable()
table.Columns.Add("DisplayColumn", GetType(String))
table.Columns.Add("HiddenColumn", GetType(String))
How to add rows to a DataTable
http://msdn.microsoft.com/en-us/libr...(v=vs.90).aspx
Here is some more conversions
Code:
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