PreferencesStore.SetValue Method

Definition

Removes, adds, or replaces an item in the preference store.

Overloads

SetValue(String, Boolean, Boolean)

Removes, adds, or replaces an item in the preference store, using the specified Boolean values.

SetValue(String, Int32, Int32)

Removes, adds, or replaces an item in the preference store, using the specified integer values.

SetValue(String, String, String)

Removes, adds, or replaces an item in the preference store, using the specified string values.

SetValue(String, Boolean, Boolean)

Removes, adds, or replaces an item in the preference store, using the specified Boolean values.

public:
 void SetValue(System::String ^ name, bool value, bool defaultValue);
public void SetValue (string name, bool value, bool defaultValue);
member this.SetValue : string * bool * bool -> unit
Public Sub SetValue (name As String, value As Boolean, defaultValue As Boolean)

Parameters

name
String

The name of the store item.

value
Boolean

The value to set for the named store item.

defaultValue
Boolean

The reset value indicator.

Exceptions

name is null or empty.

Examples

The following example saves a bool item in the store, changes the value, and then deletes the item.

void TrcBoolVal(string name) {

    PreferencesStore store = MyPrefStore;

    bool b = store.ContainsValue(name);
    Trace.WriteLine("ContainsValue(\"" + name + "\") : "
        + b.ToString());

    if (b == false)
        return;

    bool myCnfgBoolVal = store.GetValue(name, false);
    Trace.WriteLine(name + " Value: "
    + myCnfgBoolVal.ToString());

}
void TrcSetBool() {

    PreferencesStore store = MyPrefStore;

    string name = "MyBool";

    store.SetValue(name, true, false);
    TrcBoolVal(name);

    store.SetValue(name, false, true);
    TrcBoolVal(name);

    store.SetValue(name, true, true);
    TrcBoolVal(name);
}

Remarks

If the value and defaultValue parameters are the same, the item is removed from the store.

Applies to

SetValue(String, Int32, Int32)

Removes, adds, or replaces an item in the preference store, using the specified integer values.

public:
 void SetValue(System::String ^ name, int value, int defaultValue);
public void SetValue (string name, int value, int defaultValue);
member this.SetValue : string * int * int -> unit
Public Sub SetValue (name As String, value As Integer, defaultValue As Integer)

Parameters

name
String

The name of the store item.

value
Int32

The value to set for the named store item.

defaultValue
Int32

The reset value indicator.

Exceptions

name is null or empty.

Examples

The following example saves an int item in the store, changes the value, and then deletes the item.

void TrcVal(string name, int defVal) {

    PreferencesStore store = MyPrefStore;

    bool b = store.ContainsValue(name);
    if (b == false)
        Trace.WriteLine(name + " is not in store");


    int intVal = store.GetValue(name, defVal);
    Trace.WriteLine(name + " Value = "
        + intVal.ToString());

}
void TrcSetInt() {

    PreferencesStore store = MyPrefStore;
    string name = "MyInt";

    store.SetValue(name, 12, 321);
    TrcVal(name, 45678);

    store.SetValue(name, 321, 12);
    TrcVal(name, 45678);

    store.SetValue(name, 12, 12);
    TrcVal(name, 45678);
}

Remarks

If the value and defaultValue parameters are the same, this method removes the item from the store.

Applies to

SetValue(String, String, String)

Removes, adds, or replaces an item in the preference store, using the specified string values.

public:
 void SetValue(System::String ^ name, System::String ^ value, System::String ^ defaultValue);
public void SetValue (string name, string value, string defaultValue);
member this.SetValue : string * string * string -> unit
Public Sub SetValue (name As String, value As String, defaultValue As String)

Parameters

name
String

The name of the store item.

value
String

The value to set for the named store item.

defaultValue
String

The reset value indicator.

Exceptions

The name or value parameter is null or empty.

Examples

The following example saves a string item in the store, changes the value, and then deletes the item.

void TrcVal(string name, string strDefault) {

    PreferencesStore store = MyPrefStore;

    bool b = store.ContainsValue(name);
    if (b == false)
        Trace.WriteLine(name + " Not in store");

    string strVal = store.GetValue(name, strDefault);
    Trace.WriteLine(name + "Value = \""
        + strVal + "\"");

}
void TrcSetStrng() {

    PreferencesStore store = MyPrefStore;
    string name = "MyString";
    string sA = "abc";
    string sX = "X-12345";
    string sDefault = "My Default String";

    store.SetValue(name, sA, sX);
    TrcVal(name, sDefault);

    store.SetValue(name, sX, sA);
    TrcVal(name, sDefault);

    store.SetValue(name, sA, sA);
    TrcVal(name, sDefault);
}

Remarks

If the value and defaultValue parameters are the same, the item is removed from the store.

Applies to