HeaderPane
Main
Hide
Share Link
Print

SelectedValue Property, SftBox Class

Defines the value of the selected item.

Class: SftBox
Namespace: Softelvdm.SftBoxNET
Assembly: Softelvdm.SftBoxNET

Syntax

public object SelectedValue { get; set; }
Public Property SelectedValue As Object

Value

The SftBox.ValueMember value of the selected item's ItemClass.DataItem (the data source row, or the font, style or size of a font list; the DataItem itself if SftBox.ValueMember is empty), or null/Nothing if no item is selected or the item has no DataItem.

Comments

Defines the value of the selected item.

Setting the value selects the first item whose value equals it, or no item if there is none. A value set before the data source is connected is applied when it is.

Examples

C# View entire sample code

        private void FillCombo(ComboBox combo, Type enumType, object current) {
            foreach (object value in Enum.GetValues(enumType))
                combo.Items.Add(value);
            combo.SelectedItem = current;
        }

        // The sizes follow the chosen font; the preview shows the font at the chosen or typed size.
        private void sftBox3_SelectedItemChanged(object sender, EventArgs e) {
            FontFamily family = sftBox3.SelectedValue as FontFamily;
            if (family == null)
                return;
            string size = sftBox4.Text;
            sftBox4.FillFontSizes(family);
            sftBox4.Text = size.Length > 0 ? size : "12";
            UpdatePreview();
        }

VB.NET View entire sample code

        For Each value As Object In [Enum].GetValues(enumType)
            combo.Items.Add(value)
        Next
        combo.SelectedItem = current
    End Sub

    ' The sizes follow the chosen font; the preview shows the font at the chosen or typed size.
    Private Sub SftBox3_SelectedItemChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox3.SelectedItemChanged
        Dim family As FontFamily = TryCast(SftBox3.SelectedValue, FontFamily)
        If family Is Nothing Then Return
        Dim size As String = SftBox4.Text
        SftBox4.FillFontSizes(family)
        SftBox4.Text = If(size.Length > 0, size, "12")
        UpdatePreview()
    End Sub

See Also SftBox Class | Classes | SftBox/NET 3.0