Hello Luca,
Thank you for writing.
To prevent the change in the selection, in the MouseDown event of the button in the custom cell, you should set the control element Tag with some value, so later you would know whether the selection request comes from the button or not:
Then you should create a descendant of RadListView and override the OnMouseUp property and return if the Tag is filled with your value:
Here is a whole example you can test with:
protected
override
void
OnLoad(EventArgs e)
{
base
.OnLoad(e);
radListView1 =
new
MyRadListView();
radListView1.Parent =
this
;
radListView1.Dock = DockStyle.Fill;
radListView1.CellCreating += radListView1_CellCreating;
radListView1.ViewType = ListViewType.DetailsView;
DataTable dt =
new
DataTable();
dt.Columns.Add(
"Id"
,
typeof
(
int
));
dt.Columns.Add(
"Name"
,
typeof
(
string
));
for
(
int
i = 0; i < 50; i++)
{
dt.Rows.Add(i,
"Item "
+ i);
}
this
.radListView1.DataSource = dt;
}
private
void
radListView1_CellCreating(
object
sender, ListViewCellElementCreatingEventArgs e)
{
DetailListViewDataCellElement cell = e.CellElement
as
DetailListViewDataCellElement;
if
(cell !=
null
&& cell.Data.Name ==
"Name"
)
{
e.CellElement =
new
CustomDetailListViewDataCellElement(cell.RowElement, e.CellElement.Data);
}
}
class
MyRadListView : RadListView
{
protected
override
void
OnMouseUp(MouseEventArgs e)
{
if
(
this
.ListViewElement.ViewElement.Tag +
""
==
"ButtonIsClicked"
)
{
this
.ListViewElement.ViewElement.Tag =
null
;
return
;
}
base
.OnMouseUp(e);
}
public
override
string
ThemeClassName
{
get
{
return
typeof
(RadListView).FullName;
}
}
}
public
class
CustomDetailListViewDataCellElement : DetailListViewDataCellElement
{
private
RadButtonElement button;
public
CustomDetailListViewDataCellElement(DetailListViewVisualItem owner,
ListViewDetailColumn column) :
base
(owner, column)
{
}
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
this
.button =
new
RadButtonElement();
button.MouseDown += Button_MouseDown;
this
.Children.Add(
this
.button);
}
private
void
Button_MouseDown(
object
sender, MouseEventArgs e)
{
this
.RowElement.CellsContainer.Context.Tag =
"ButtonIsClicked"
;
}
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(DetailListViewHeaderCellElement);
}
}
public
override
void
Synchronize()
{
base
.Synchronize();
this
.Text =
""
;
DataRowView rowView =
this
.Row.DataBoundItem
as
DataRowView;
this
.button.Text = rowView.Row[
"Name"
].ToString();
}
public
override
bool
IsCompatible(ListViewDetailColumn data,
object
context)
{
if
(data.Name !=
"Name"
)
{
return
false
;
}
return
base
.IsCompatible(data, context);
}
}
I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.
Regards,
Stefan
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