Re: Combobox Store Values
Given a color name
Code:
Me.BackColor = ColorTranslator.FromHtml("Blue")
http://msdn.microsoft.com/en-us/libr...ranslator.aspx
Re: Combobox Store Values
I need to save a name together with a hex value, but the value should be hidden. Save the Data along with the name.
Im new to this sry.
Re: Combobox Store Values
Quote:
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
Re: Combobox Store Values
As i said, im very new to this program, cloud be nice with some exsample.
I Dont know what to add and where?
Heres my code so far:
vb Code:
Private Sub Button1_Click_2(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If WCComboColors.Text.Length = 0 Then
MsgBox("Please enter a name.")
ElseIf WCComboColors.Items.Contains(WCComboColors.Text) Then
MsgBox("The name: " & "'" & WCComboColors.Text & "'" & " already exsist.")
Else
MsgBox("'" & WCComboColors.Text & "'" & " was added to the list.")
' THIS WILL SAVE WHATEVER THE USERS WAS WRITTEN IN THE COMBOBOX.
' NOW I JUST NEED TO SAVE THE VALUES (HEX VALUE, FROM A BACKGROUND COLOR OF A PANEL), ALONG WITH THE NAME.
' SO IF A USER PRESSES ORANGE, THE ORANGE HEX VALUE COLOR APPEARS IN A BACKGROUND COLOR OF A PANEL.
' THE USER SHOULD ALSO BE ABLE TO DELETE VALUES/NAMES.
' I DONT KNOW HOW TO SAVE/LOAD THIS DATA?
WCComboColors.Items.Add(WCComboColors.Text)
End If
End Sub
Private Sub Button2_Click_1(sender As System.Object, e As System.EventArgs) Handles Button2.Click
MsgBox("'" & WCComboColors.Text & "'" & " was deleted from the list.")
WCComboColors.Items.Remove(WCComboColors.SelectedItem)
WCComboColors.Text = ""
ColorBox.BackColor = Color.Black
End Sub
Re: Combobox Store Values
Re: Combobox Store Values
Quote:
Originally Posted by
crusher
bump
The only thing bumping will get you is this. Do not bump