ItemCheckEventArgs.NewValue Property


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

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public CheckState NewValue { get; set; }

Property Value

Type: System.Windows.Forms.CheckState

One of the CheckState values.

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.

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.AppendFormat("{0} = {1}", "NewValue", e.NewValue );
messageBoxCS.AppendFormat("{0} = {1}", "CurrentValue", e.CurrentValue );
MessageBox.Show(messageBoxCS.ToString(), "ItemCheck Event" );

.NET Framework
Available since 1.1
Return to top