Occurs after the value of the
UltraListViewItem.CheckState property of an
UltraListViewItem has been changed.
Syntax
Example
The following code sample demonstrates how to handle the UltraListView's ItemCheckStateChanging and ItemCheckStateChanged events to allow only one checked item per group, and to activate and select the checked item after it is checked:
For an overview of how to handle events in Visual Basic or Visual C#, see
Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see
Consuming Events in the
.NET Framework Developer's Guide.
| Visual Basic | Copy Code |
|---|
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinListView
Private Sub ultraListView1_ItemCheckStateChanging(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinListView.ItemCheckStateChangingEventArgs) Handles ultraListView1.ItemCheckStateChanging
Dim listView As UltraListView = CType(sender, UltraListView)
Try
listView.EventManager.Disable(UltraListViewEventIds.ItemCheckStateChanging)
listView.EventManager.Disable(UltraListViewEventIds.ItemCheckStateChanged)
If listView.ShowGroups AndAlso e.NewValue = CheckState.Checked Then
Dim group As UltraListViewGroup = e.Item.Group
Dim item As UltraListViewItem
For Each item In group.Items
If Not item Is e.Item Then item.CheckState = CheckState.Unchecked
Next
End If
Finally
listView.EventManager.Enable(UltraListViewEventIds.ItemCheckStateChanging)
listView.EventManager.Enable(UltraListViewEventIds.ItemCheckStateChanged)
End Try
End Sub
Private Sub ultraListView1_ItemCheckStateChanged(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinListView.ItemCheckStateChangedEventArgs) Handles ultraListView1.ItemCheckStateChanged
Dim listView As UltraListView = CType(sender, UltraListView)
e.Item.Activate()
listView.PerformAction(UltraListViewAction.SelectItem, False, False)
End Sub |
| C# | Copy Code |
|---|
using Infragistics.Win; using Infragistics.Win.UltraWinListView; using System.Diagnostics;
private void ultraListView1_ItemCheckStateChanging(object sender,
Infragistics.Win.UltraWinListView.ItemCheckStateChangingEventArgs e)
{
UltraListView listView = sender as UltraListView;
try
{
// Disable the
ItemCheckStateChanging and ItemCheckStateChanged events,
// so that we don't
cause infinite recursion by setting the CheckState
// property in response
to this event.
listView.EventManager.Disable(UltraListViewEventIds.ItemCheckStateChanging);
listView.EventManager.Disable(UltraListViewEventIds.ItemCheckStateChanged);
if (
listView.ShowGroups && e.NewValue == CheckState.Checked )
{
UltraListViewGroup group = e.Item.Group;
//
Iterate the group's Items collection, and uncheck
//
all other items except for this one
foreach( UltraListViewItem item in group.Items )
{
if ( item != e.Item )
item.CheckState
= CheckState.Unchecked;
}
}
}
finally
{
// Re-enable the
ItemCheckStateChanging and ItemCheckStateChanged events.
listView.EventManager.Enable(UltraListViewEventIds.ItemCheckStateChanging);
listView.EventManager.Enable(UltraListViewEventIds.ItemCheckStateChanged);
}
}
private void ultraListView1_ItemCheckStateChanged(object sender,
Infragistics.Win.UltraWinListView.ItemCheckStateChangedEventArgs e)
{
UltraListView listView = sender as UltraListView;
// Activate and select the item that was
checked
e.Item.Activate();
listView.PerformAction( UltraListViewAction.SelectItem, false, false );
}
|
See Also