Duc Hoang Viet
Top achievements
Rank 1
Duc Hoang Viet
asked on 17 Oct 2009, 05:18 PM
In beta 2, I used to addHandler for GridViewCell's MouseDoubleClickEvent to handler event double click on one row. But in beta 3, this seem not working. Is there any way to fix this?
5 Answers, 1 is accepted
0
Hi Duc Hoang Viet,
Best wishes,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Thank you for reporting this issue. We will fix it for the official Q3 release. For the time being you can use the following workaround: This a class that we use in RadGridView to implement double clicks:\
public
class
DoubleClick
{
private
UIElement element;
private
DispatcherTimer doubleClickTimer;
private
int
clickCount;
internal
event
EventHandler DoubleClickEvent;
public
DoubleClick(UIElement element)
{
this
.element = element;
this
.element.AddHandler(UIElement.MouseLeftButtonDownEvent,
new
MouseButtonEventHandler(element_MouseLeftButtonDown),
true
);
}
void
element_MouseLeftButtonDown(
object
sender, MouseButtonEventArgs e)
{
this
.StartDoubleClickTime();
if
(
this
.clickCount > 0)
this
.OnDoubleClick();
this
.clickCount++;
}
private
void
StartDoubleClickTime()
{
if
(
this
.doubleClickTimer !=
null
)
{
this
.doubleClickTimer.Stop();
}
this
.doubleClickTimer =
new
DispatcherTimer();
this
.doubleClickTimer.Interval = TimeSpan.FromMilliseconds(300);
this
.doubleClickTimer.Tick +=
new
EventHandler(doubleClickTimer_Tick);
this
.doubleClickTimer.Start();
}
void
doubleClickTimer_Tick(
object
sender, EventArgs e)
{
this
.doubleClickTimer.Stop();
this
.clickCount = 0;
}
private
void
OnDoubleClick()
{
if
(
this
.DoubleClickEvent !=
null
)
this
.DoubleClickEvent(
this
.element,
new
EventArgs());
}
}
Once you have this class in your project you just have to utilize it to be able to handle MouseDoubleCLick events:
public
MainPage()
{
InitializeComponent();
this
.playersGrid.ItemsSource = Club.GetPlayers();
this
.playersGrid.RowLoaded +=
new
System.EventHandler<Telerik.Windows.Controls.GridView.RowLoadedEventArgs>(playersGrid_RowLoaded);
}
void
playersGrid_RowLoaded(
object
sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
{
if
(e.Row
is
GridViewHeaderRow || e.Row
is
GridViewNewRow || e.Row
is
GridViewFooterRow)
return
;
var row = e.Row
as
GridViewRow;
foreach
(var item
in
row.Cells)
{
DoubleClick click =
new
DoubleClick(item);
click.DoubleClickEvent +=
new
System.EventHandler(click_DoubleClickEvent);
}
}
void
click_DoubleClickEvent(
object
sender, System.EventArgs e)
{
}
Hope this is helpful.
Best wishes,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
david ocasio
Top achievements
Rank 1
answered on 22 Oct 2009, 04:14 PM
I beleive the "internal" has to be removed from
At least in my code it had to
since i put class "DoubleClick" in a class library.
thanks
dco
internal
event
EventHandler DoubleClickEvent
At least in my code it had to
since i put class "DoubleClick" in a class library.
thanks
dco
0
Hello david ocasio,
Yes, you are absolutely correct. I forgot to remove it.
Best wishes,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Yes, you are absolutely correct. I forgot to remove it.
Best wishes,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Damian Andrade
Top achievements
Rank 1
answered on 26 Oct 2009, 07:13 PM
I have same problem, but in this screen not exits cells in my row, after run event RowLoaded is present the row in the grid and not atach to event double click but not cells
0
Hi Damian Andrade,
Sincerely yours,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
This is a known issue in Beta 2. You could workaround that limitation by subscribing to the DoubleClickEvent of RadGridView and in the DoubleClickEvent handler check if the clicked element is cell. Here is a sample solution with a minor modification to the DoubleClick class:
public
MainPage()
{
InitializeComponent();
this
.playersGrid.ItemsSource = Club.GetPlayers();
DoubleClick click =
new
DoubleClick(
this
.playersGrid);
click.DoubleClickEvent +=
new
System.Windows.Input.MouseButtonEventHandler(click_DoubleClickEvent);
}
void
click_DoubleClickEvent(
object
sender, System.Windows.Input.MouseButtonEventArgs e)
{
FrameworkElement clickedElement = sender
as
FrameworkElement;
if
(clickedElement
is
GridViewCell)
{
// cell was clicked
}
else
{
var cell = clickedElement.ParentOfType<GridViewCell>();
if
(cell !=
null
)
{
// cell was clicked
}
}
}
public
class
DoubleClick
{
private
UIElement element;
private
DispatcherTimer doubleClickTimer;
private
int
clickCount;
internal
event
MouseButtonEventHandler DoubleClickEvent;
public
DoubleClick(UIElement element)
{
this
.element = element;
this
.element.AddHandler(UIElement.MouseLeftButtonDownEvent,
new
MouseButtonEventHandler(element_MouseLeftButtonDown),
true
);
}
void
element_MouseLeftButtonDown(
object
sender, MouseButtonEventArgs e)
{
this
.StartDoubleClickTime();
if
(
this
.clickCount > 0)
this
.OnDoubleClick(e);
this
.clickCount++;
}
private
void
StartDoubleClickTime()
{
if
(
this
.doubleClickTimer !=
null
)
{
this
.doubleClickTimer.Stop();
}
this
.doubleClickTimer =
new
DispatcherTimer();
this
.doubleClickTimer.Interval = TimeSpan.FromMilliseconds(300);
this
.doubleClickTimer.Tick +=
new
EventHandler(doubleClickTimer_Tick);
this
.doubleClickTimer.Start();
}
void
doubleClickTimer_Tick(
object
sender, EventArgs e)
{
this
.doubleClickTimer.Stop();
this
.clickCount = 0;
}
private
void
OnDoubleClick(MouseButtonEventArgs args)
{
if
(
this
.DoubleClickEvent !=
null
)
this
.DoubleClickEvent(
this
.element, args);
}
}
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.