ComboBox DisplayMember and ValueMember without database
-
I use this
color1 = New BaseColor() {iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLUE, iTextSharp.text.BaseColor.CYAN, iTextSharp.text.BaseColor.DARK_GRAY, iTextSharp.text.BaseColor.GRAY, iTextSharp.text.BaseColor.GREEN, iTextSharp.text.BaseColor.LIGHT_GRAY, iTextSharp.text.BaseColor.MAGENTA, iTextSharp.text.BaseColor.ORANGE, iTextSharp.text.BaseColor.PINK, iTextSharp.text.BaseColor.RED, iTextSharp.text.BaseColor.WHITE, iTextSharp.text.BaseColor.YELLOW}
color2 = New String() {"Черен", "Син", "Циан", "Тъмно сиво", "Сиво", "Зелено", "Светло сиво", "Магента", "Оранжево", "Розово", "Червено", "Бяло", "Жълто"}
For i = 0 To color1.Length - 1
ComboBox2.Items.Add(color2(i))
NextIf File.Exists(TextBox1.Text) Then
File.Delete(TextBox1.Text)
Dim bf As BaseFont = BaseFont.CreateFont(k & "\\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)
Dim bc As BaseColor
bc = color1(ComboBox2.SelectedIndex)
' bc = CType(iTextSharp.text.BaseColor.BLACK, "BaseColor" & "." & color1(ComboBox2.SelectedIndex))AddWatermarkText(TextBox3.Text, TextBox1.Text, TextBox2.Text, bf, NumericUpDown1.Value, bc, 50.0F, NumericUpDown2.Value) Else Dim bf As BaseFont = BaseFont.CreateFont(k & "\\\\arial.ttf", BaseFont.IDENTITY\_H, BaseFont.EMBEDDED) Dim bc As BaseColor bc = color1(ComboBox2.SelectedIndex) ' bc = CType(iTextSharp.text.BaseColor.BLACK, "BaseColor" & "." & color1(ComboBox2.SelectedIndex)) AddWatermarkText(TextBox3.Text, TextBox1.Text, TextBox2.Text, bf, NumericUpDown1.Value, bc, 50.0F, NumericUpDown2.Value) End If
-
There is no need for a database, a DataTable, or anything pre-existing. You want some class, with at least two public properties, and a collection of instances of said class. The collection (e.g. a List) becomes your DataSource; the one string property your DisplayMember, and the other property your ValueMember; so you need to provide the names of those properties in the "DisplayMember" and "ValueMember" properties of your Control (e.g. ComboBox). :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
There is no need for a database, a DataTable, or anything pre-existing. You want some class, with at least two public properties, and a collection of instances of said class. The collection (e.g. a List) becomes your DataSource; the one string property your DisplayMember, and the other property your ValueMember; so you need to provide the names of those properties in the "DisplayMember" and "ValueMember" properties of your Control (e.g. ComboBox). :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
This work for me thanks
Public Class WatermarColors
Private mWatermarkColor As iTextSharp.text.BaseColor
Private mWatermarkBGName As StringPublic Sub New(ByVal name As String, ByVal code As iTextSharp.text.BaseColor) mWatermarkBGName = name mWatermarkColor = code End Sub Public Property WatermarkBGNames() As String Get Return mWatermarkBGName End Get Set(ByVal value As String) mWatermarkBGName = value End Set End Property Public Property WatermarkColors() As iTextSharp.text.BaseColor Get Return mWatermarkColor End Get Set(ByVal value As iTextSharp.text.BaseColor) mWatermarkColor = value End Set End Property Public Overrides Function ToString() As String Return mWatermarkBGName End Function
End Class
color1 = New BaseColor() {iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLUE, iTextSharp.text.BaseColor.CYAN, iTextSharp.text.BaseColor.DARK_GRAY, iTextSharp.text.BaseColor.GRAY, iTextSharp.text.BaseColor.GREEN, iTextSharp.text.BaseColor.LIGHT_GRAY, iTextSharp.text.BaseColor.MAGENTA, iTextSharp.text.BaseColor.ORANGE, iTextSharp.text.BaseColor.PINK, iTextSharp.text.BaseColor.RED, iTextSharp.text.BaseColor.WHITE, iTextSharp.text.BaseColor.YELLOW}
color2 = New String() {"Черен", "Син", "Циан", "Тъмно сиво", "Сиво", "Зелено", "Светло сиво", "Магента", "Оранжево", "Розово", "Червено", "Бяло", "Жълто"}
For i = 0 To color1.Length - 1
CboWatermarkColor.Items.Add(New WatermarColors(color2(i), color1(i)))
NextPrivate Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If File.Exists(TextBox1.Text) Then
File.Delete(TextBox1.Text)
Dim bf As BaseFont = BaseFont.CreateFont(k & "\\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)
Dim bc As BaseColor
Dim WatermarkSelectColor As WatermarColorsWatermarkSelectColor = CType(CboWatermarkColor.SelectedItem, WatermarColors) bc = WatermarkSelectColor.WatermarkColors AddWatermarkText(TextBox3.Text, TextBox1.Text, TextBox2.Text, bf, NumericUpDown1.Value, bc, 50.0F, NumericUpDown2.Value) Else Dim bf As BaseFont = BaseFont.CreateFont(k & "\\\\arial.ttf", BaseFont.IDENTITY\_H, BaseFont.EMBEDDED) Dim bc As Base
-
This work for me thanks
Public Class WatermarColors
Private mWatermarkColor As iTextSharp.text.BaseColor
Private mWatermarkBGName As StringPublic Sub New(ByVal name As String, ByVal code As iTextSharp.text.BaseColor) mWatermarkBGName = name mWatermarkColor = code End Sub Public Property WatermarkBGNames() As String Get Return mWatermarkBGName End Get Set(ByVal value As String) mWatermarkBGName = value End Set End Property Public Property WatermarkColors() As iTextSharp.text.BaseColor Get Return mWatermarkColor End Get Set(ByVal value As iTextSharp.text.BaseColor) mWatermarkColor = value End Set End Property Public Overrides Function ToString() As String Return mWatermarkBGName End Function
End Class
color1 = New BaseColor() {iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLUE, iTextSharp.text.BaseColor.CYAN, iTextSharp.text.BaseColor.DARK_GRAY, iTextSharp.text.BaseColor.GRAY, iTextSharp.text.BaseColor.GREEN, iTextSharp.text.BaseColor.LIGHT_GRAY, iTextSharp.text.BaseColor.MAGENTA, iTextSharp.text.BaseColor.ORANGE, iTextSharp.text.BaseColor.PINK, iTextSharp.text.BaseColor.RED, iTextSharp.text.BaseColor.WHITE, iTextSharp.text.BaseColor.YELLOW}
color2 = New String() {"Черен", "Син", "Циан", "Тъмно сиво", "Сиво", "Зелено", "Светло сиво", "Магента", "Оранжево", "Розово", "Червено", "Бяло", "Жълто"}
For i = 0 To color1.Length - 1
CboWatermarkColor.Items.Add(New WatermarColors(color2(i), color1(i)))
NextPrivate Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If File.Exists(TextBox1.Text) Then
File.Delete(TextBox1.Text)
Dim bf As BaseFont = BaseFont.CreateFont(k & "\\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)
Dim bc As BaseColor
Dim WatermarkSelectColor As WatermarColorsWatermarkSelectColor = CType(CboWatermarkColor.SelectedItem, WatermarColors) bc = WatermarkSelectColor.WatermarkColors AddWatermarkText(TextBox3.Text, TextBox1.Text, TextBox2.Text, bf, NumericUpDown1.Value, bc, 50.0F, NumericUpDown2.Value) Else Dim bf As BaseFont = BaseFont.CreateFont(k & "\\\\arial.ttf", BaseFont.IDENTITY\_H, BaseFont.EMBEDDED) Dim bc As Base
Dim lst as New List(Of WatermarkColor)
lst.Add(New WatermarkColor(watermarkBGName,watermarkColor)cboWatermarkColors.DataSource = lst
cboWatermarkColors.DisplayMember = "WatermarkBGName"
cboWatermarkColors.ValueMember = "WatermarkColor"I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife