We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to determine which item was selected In the GroupView.GroupViewItemSelected event handler

 

The GroupView control’s SelectedItem property returns the index of the item selecting which triggered the GroupViewItemSelected event.

Important: Please note that when the GroupView control is used in the non-ButtonView mode, the SelectedItem index is a transient value and is valid only as long as the cursor remains over the item that was clicked. This is by design intent as moving the cursor away from the selected/highlighted item will transfer it to a non-selected/non-highlighted state. If certain tasks, such as displaying a message box, that would transfer the cursor/focus from the control are likely to be performed within the event handler, then it is imperative that a local reference to the selected index be cached beforehand. This is demonstrated in the following code:

C#

private void gvcPersonal_GroupViewItemSelected(object sender, System.EventArgs e)

{

int nselected = this.gvcPersonal.SelectedItem;

 if(nselected >= 0)

 {

MessageBox.Show(this.gvcPersonal.GroupViewItems[nselected].Text);

Trace.WriteLine(this.gvcPersonal.GroupViewItems[nselected].Text);

 }

}

VB

Private  Sub gvcPersonal_GroupViewItemSelected(ByVal sender As Object, ByVal e As System.EventArgs)

 Dim nselected As Integer =  Me.gvcPersonal.SelectedItem

 If nselected >= 0 Then

   MessageBox.Show(Me.gvcPersonal.GroupViewItems(nselected).Text)

Trace.WriteLine(Me.gvcPersonal.GroupViewItems(nselected).Text)

 End If

End Sub

Article ID: Published Date: Last Revised Date: Platform: Control:
1061 04/30/2011 07/10/2014 Windows Forms GroupView
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.