Breyta

Deila með


ItemCheckEventArgs.NewValue Property

Definition

Gets or sets a value indicating whether to set the check box for the item to be checked, unchecked, or indeterminate.

public:
 property System::Windows::Forms::CheckState NewValue { System::Windows::Forms::CheckState get(); void set(System::Windows::Forms::CheckState value); };
public System.Windows.Forms.CheckState NewValue { get; set; }
member this.NewValue : System.Windows.Forms.CheckState with get, set
Public Property NewValue As CheckState

Property Value

One of the CheckState values.

Examples

The following code example demonstrates the use of this member. In the example, an event handler reports on the occurrence of the CheckedListBox.ItemCheck event. This report helps you to learn when the event occurs and can assist you in debugging. To report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.

To run the example code, paste it into a project that contains an instance of type CheckedListBox named CheckedListBox1. Then ensure that the event handler is associated with the CheckedListBox.ItemCheck event.

private void CheckedListBox1_ItemCheck(Object sender, ItemCheckEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "Index", e.Index );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "NewValue", e.NewValue );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "CurrentValue", e.CurrentValue );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "ItemCheck Event" );
}
Private Sub CheckedListBox1_ItemCheck(sender as Object, e as ItemCheckEventArgs) _ 
     Handles CheckedListBox1.ItemCheck

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "Index", e.Index)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "NewValue", e.NewValue)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "CurrentValue", e.CurrentValue)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"ItemCheck Event")

End Sub

Remarks

This property enables you to determine the new check state for the specified item before the check state is changed by the CheckedListBox control. In addition to determining the new check state, you can use this property in an event handler for the ItemCheck event to change the state to a different check state than the one specified. For example, if the user placed a check mark next to an item in the CheckedListBox that you have determined should not be checked based on the state of your application, you can override the change in the check mark state by setting this property to its previous setting or to a different check state.

Applies to

See also