Export (0) Print
Expand All

DomainUpDown.OnSelectedItemChanged Method

Raises the SelectedItemChanged event.

[Visual Basic]
Protected Sub OnSelectedItemChanged( _
   ByVal source As Object, _
   ByVal e As EventArgs _
)
[C#]
protected void OnSelectedItemChanged(
 object source,
 EventArgs e
);
[C++]
protected: void OnSelectedItemChanged(
 Object* source,
 EventArgs* e
);
[JScript]
protected function OnSelectedItemChanged(
   source : Object,
 e : EventArgs
);

Parameters

source
The source of the event.
e
An EventArgs that contains the event data.

Remarks

Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.

The OnSelectedItemChanged method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

Notes to Inheritors:  When overriding OnSelectedItemChanged in a derived class, be sure to call the base class's OnSelectedItemChanged method so that registered delegates receive the event.

Example

[Visual Basic, C#, C++] The following example creates and initializes a DomainUpDown control. The example allows you to set some of its properties and create a collection of strings for display in the up-down control. The code assumes that a TextBox, CheckBox and a Button have been instantiated on a form. The example also assumes that you have a member variable at the class level declared as a 32-bit signed integer named myCounter. You can enter a string in the text box and add it to the Items collection when the button is clicked. By clicking the check box, you can toggle the Sorted property and observe the difference in the collection of items in the up-down control.

[Visual Basic] 
Protected domainUpDown1 As DomainUpDown


Private Sub MySub()
    ' Create and initialize the DomainUpDown control.
    domainUpDown1 = New System.Windows.Forms.DomainUpDown()
    
    ' Add the DomainUpDown control to the form.
    Controls.Add(domainUpDown1)
End Sub 'MySub


Private Sub button1_Click(sender As System.Object, e As System.EventArgs)
    ' Add the text box contents and initial location in the collection
    ' to the DomainUpDown control.
    domainUpDown1.Items.Add((textBox1.Text.Trim() & " - " & myCounter))
    
    ' Increment the counter variable.
    myCounter = myCounter + 1
    
    ' Clear the TextBox.
    textBox1.Text = ""
End Sub 'button1_Click


Private Sub checkBox1_Click(sender As System.Object, e As System.EventArgs)
    ' If Sorted is set to true, set it to false; 
    ' otherwise set it to true.
    If domainUpDown1.Sorted Then
        domainUpDown1.Sorted = False
    Else
        domainUpDown1.Sorted = True
    End If
End Sub 'checkBox1_Click


Private Sub domainUpDown1_SelectedItemChanged _
    (sender As System.Object, e As System.EventArgs)
    
    ' Display the SelectedIndex and SelectedItem property values in a MessageBox.
    MessageBox.Show(("SelectedIndex: " & domainUpDown1.SelectedIndex.ToString() & _
        ControlChars.Cr & "SelectedItem: " & domainUpDown1.SelectedItem.ToString()))
End Sub 'domainUpDown1_SelectedItemChanged

[C#] 
protected DomainUpDown domainUpDown1;

private void MySub()
 {
    // Create and initialize the DomainUpDown control.
    domainUpDown1 = new System.Windows.Forms.DomainUpDown();
    
    // Add the DomainUpDown control to the form.
    Controls.Add(domainUpDown1);
 }
 
 private void button1_Click(System.Object sender, 
                           System.EventArgs e)
 {   
    // Add the text box contents and initial location in the collection
    // to the DomainUpDown control.
    domainUpDown1.Items.Add((textBox1.Text.Trim()) + " - " + myCounter);
    
    // Increment the counter variable.
    myCounter = myCounter + 1;
 
    // Clear the TextBox.
    textBox1.Text = "";
 }
 
 private void checkBox1_Click(System.Object sender, 
                             System.EventArgs e)
 {
    // If Sorted is set to true, set it to false; 
    // otherwise set it to true.
    if (domainUpDown1.Sorted)
    {
       domainUpDown1.Sorted = false;
    }
    else
    {
       domainUpDown1.Sorted = true;
    }
 }
 
 private void domainUpDown1_SelectedItemChanged(System.Object sender, 
                                               System.EventArgs e)
 {
    // Display the SelectedIndex and SelectedItem property values in a MessageBox.
    MessageBox.Show("SelectedIndex: " + domainUpDown1.SelectedIndex.ToString() 
       + "\n" + "SelectedItem: " + domainUpDown1.SelectedItem.ToString());
 }


[C++] 
protected:
    DomainUpDown __gc *domainUpDown1;

private:
    void MySub() {
        // Create and initialize the DomainUpDown control.
        domainUpDown1 = new System::Windows::Forms::DomainUpDown();
    
        // Add the DomainUpDown control to the form.
        Controls->Add(domainUpDown1);
    };
 
    void button1_Click(Object *sender, EventArgs *e) {   
        // Add the text box contents and initial location in the collection
        // to the DomainUpDown control.
        domainUpDown1->Items->Add(String::Concat((textBox1->Text->Trim()), S" - ", __box(myCounter)->ToString()));
    
        // Increment the counter variable.
        myCounter = myCounter + 1;
 
        // Clear the TextBox.
        textBox1->Text = S"";
    };
 
    void checkBox1_Click(Object *sender, EventArgs *e) {
        // If Sorted is set to true, set it to false; 
        // otherwise set it to true.
        if (domainUpDown1->Sorted) {
            domainUpDown1->Sorted = false;
        } else {
            domainUpDown1->Sorted = true;
        }
    };
 
    void domainUpDown1_SelectedItemChanged(Object *sender, EventArgs *e) {
        // Display the SelectedIndex and SelectedItem property values in a MessageBox.
        MessageBox::Show(String::Concat(S"SelectedIndex: ", __box(domainUpDown1->SelectedIndex)->ToString(), 
        S"\n", S"SelectedItem: ", domainUpDown1->SelectedItem->ToString()));
    };

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DomainUpDown Class | DomainUpDown Members | System.Windows.Forms Namespace | SelectedItem | SelectedItemChanged

Show:
© 2014 Microsoft