Javier Gonzalez de Aragon
Top achievements
Rank 2
Javier Gonzalez de Aragon
asked on 28 May 2012, 08:05 PM
Is it possible to select an item in a ListView using the mouse right button?
Thanks,
Javier Gonzalez de Aragon
Thanks,
Javier Gonzalez de Aragon
10 Answers, 1 is accepted
0
Hello Javier,
Thank you for your question.
Currently, RadListView does not provide such a built-in option, but you can achieve this behavior by handling the MouseUp event of your RadListView. The following code snippet demonstrates this:
I hope you find this useful. In case you have any additional questions, do not hesitate to ask.
Greetings,
Ivan Todorov
the Telerik team
Thank you for your question.
Currently, RadListView does not provide such a built-in option, but you can achieve this behavior by handling the MouseUp event of your RadListView. The following code snippet demonstrates this:
void
radListView1_MouseUp(
object
sender, MouseEventArgs e)
{
if
(e.Button == System.Windows.Forms.MouseButtons.Right)
{
BaseListViewVisualItem item =
this
.radListView1.ElementTree.GetElementAtPoint(e.Location)
as
BaseListViewVisualItem;
if
(item !=
null
)
{
this
.radListView1.SelectedItem = item.Data;
}
}
}
I hope you find this useful. In case you have any additional questions, do not hesitate to ask.
Greetings,
Ivan Todorov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Javier Gonzalez de Aragon
Top achievements
Rank 2
answered on 31 May 2012, 05:36 PM
Thanks for the reply. I'm using Visual Basic and used the following code:
but nothing happens.
Any ideas?
Thanks,
Javier Gonzalez de Aragon
If (e.Button = System.Windows.Forms.MouseButtons.Right) Then
Dim item As BaseListViewVisualItem = TryCast(lvMovimientos.ElementTree.GetElementAtPoint(e.Location), BaseListViewVisualItem)
If (item IsNot Nothing) Then
lvMovimientos.SelectedItem = item.Data
End If
End If
but nothing happens.
Any ideas?
Thanks,
Javier Gonzalez de Aragon
0
Hello Javier,
I have tested the code you have posted in VB and it works correctly. Please make sure that your event handler is properly fired. Here is the full code of the handler in VB:
Please let me know if you are still experiencing difficulties.
Greetings,
Ivan Todorov
the Telerik team
I have tested the code you have posted in VB and it works correctly. Please make sure that your event handler is properly fired. Here is the full code of the handler in VB:
Private
Sub
RadListView1_MouseUp(sender
As
System.
Object
, e
As
System.Windows.Forms.MouseEventArgs)
Handles
RadListView1.MouseUp
If
(e.Button = System.Windows.Forms.MouseButtons.Right)
Then
Dim
item
As
BaseListViewVisualItem = TryCast(RadListView1.ElementTree.GetElementAtPoint(e.Location), BaseListViewVisualItem)
If
(item IsNot
Nothing
)
Then
RadListView1.SelectedItem = item.Data
End
If
End
If
End
Sub
Please let me know if you are still experiencing difficulties.
Greetings,
Ivan Todorov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Javier Gonzalez de Aragon
Top achievements
Rank 2
answered on 01 Jun 2012, 06:53 PM
If I remove the TryCast, I get the following exception:
System.InvalidCastException was unhandled
Message=Unable to cast object of type 'Telerik.WinControls.UI.DetailListViewDataCellElement' to type 'Telerik.WinControls.UI.BaseListViewVisualItem'.
Any ideas?
Regards,
Javier
System.InvalidCastException was unhandled
Message=Unable to cast object of type 'Telerik.WinControls.UI.DetailListViewDataCellElement' to type 'Telerik.WinControls.UI.BaseListViewVisualItem'.
Any ideas?
Regards,
Javier
0
Accepted
Hello Javier,
The code I have previously posted is valid for RadListView in ListView or IconView mode. When your RadListView is in DetailView mode, it has some more complex structure of rows, columns and cells. Here is how you can achieve the desired behavior when RadListView is in DetailView mode:
I hope this helps. Do not hesitate to ask if you have any further questions.
Kind regards,
Ivan Todorov
the Telerik team
The code I have previously posted is valid for RadListView in ListView or IconView mode. When your RadListView is in DetailView mode, it has some more complex structure of rows, columns and cells. Here is how you can achieve the desired behavior when RadListView is in DetailView mode:
Private
Sub
RadListView1_MouseUp(sender
As
System.
Object
, e
As
System.Windows.Forms.MouseEventArgs)
Handles
RadListView1.MouseUp
If
e.Button = Windows.Forms.MouseButtons.Right
Then
Dim
clickedCell = TryCast(
Me
.RadListView1.ElementTree.GetElementAtPoint(e.Location), DetailListViewDataCellElement)
If
clickedCell IsNot
Nothing
Then
Me
.RadListView1.SelectedItem = clickedCell.Row
Me
.RadListView1.CurrentColumn = clickedCell.Data
End
If
End
If
End
Sub
I hope this helps. Do not hesitate to ask if you have any further questions.
Kind regards,
Ivan Todorov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Javier Gonzalez de Aragon
Top achievements
Rank 2
answered on 07 Jun 2012, 06:14 PM
Thanks, that did the trick.
Javier
Javier
0
Cesar
Top achievements
Rank 1
answered on 16 May 2014, 12:14 AM
Always Null?
Missing property?
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
BaseListViewVisualItem item = this.lvwDetalle.ElementTree.GetElementAtPoint(e.Location) as BaseListViewVisualItem;
if (item != null)
{
//this.radListView1.SelectedItem = item.Data;
}
Missing property?
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
BaseListViewVisualItem item = this.lvwDetalle.ElementTree.GetElementAtPoint(e.Location) as BaseListViewVisualItem;
if (item != null)
{
//this.radListView1.SelectedItem = item.Data;
}
0
Hello Ceasar,
I am sorry, but I am unable to understand your inquiry. Can you please elaborate?
Regards,
Stefan
Telerik
I am sorry, but I am unable to understand your inquiry. Can you please elaborate?
Regards,
Stefan
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
0
Minkook
Top achievements
Rank 1
answered on 18 Jan 2016, 07:37 AM
all of comment are wrong
For find that when i click right button in radlistview spend fucking 2 days
this code is as below
[radview type is detail]
private void lv_local_MouseUp(object sender, MouseEventArgs e)
{
var lv = sender as RadListView;
var item = lv.ElementTree.GetElementAtPoint(e.Location) as DetailListViewDataCellElement;
if (item != null)
{
lv.SelectedItem = item.RowElement.Data;
}
}
0
Hello Minkook,
Thank you for writing.
The provided solution by IvanT Todorov from 06-Jun-2012 demonstrates a similar approach for accessing the right clicked DetailListViewDataCellElement. However, it directly uses the RadListView control, but you use the sender which is similar. If you have any additional questions, please let me know.
Regards,
Dess
Telerik
Thank you for writing.
The provided solution by IvanT Todorov from 06-Jun-2012 demonstrates a similar approach for accessing the right clicked DetailListViewDataCellElement. However, it directly uses the RadListView control, but you use the sender which is similar. If you have any additional questions, please let me know.
Regards,
Dess
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items