I'm using the ListView with DetailsView layout and would like to have two "normal/text" columns and one a dropdown column.
I have tried your Custom Items example and got it working, but I dont want all columns to be custom, only (the last) one.
Is it possible to have different column types with the ListView or should I go for the Grid instead?
Regards
Kenneth
I have tried your Custom Items example and got it working, but I dont want all columns to be custom, only (the last) one.
Is it possible to have different column types with the ListView or should I go for the Grid instead?
Regards
Kenneth
3 Answers, 1 is accepted
0
Hi Kenneth,
Currently, RadListView does not support different column types, but you can achieve this using its events.
I am not sure if you want to use custom cells or custom editors. In case you want the third column to be edited by drop-down editors you can handle the EditorRequired event the following way:
If you want to use visually customized cells, then you can use the CellCreating event to apply your custom cell. Here is a short example:
In this case it seems better to use GridView instead, since it provides typed columns which you can use out of the box.
I hope this was helpful. Should you have further questions, do not hesitate to contact me.
Best wishes,
Ivan Todorov
the Telerik team
Currently, RadListView does not support different column types, but you can achieve this using its events.
I am not sure if you want to use custom cells or custom editors. In case you want the third column to be edited by drop-down editors you can handle the EditorRequired event the following way:
void
radListView1_EditorRequired(
object
sender, Telerik.WinControls.UI.ListViewItemEditorRequiredEventArgs e)
{
if
(
this
.radListView1.CurrentColumn ==
this
.radListView1.Columns[2])
{
ListViewDropDownListEditor editor =
new
ListViewDropDownListEditor();
(editor.EditorElement
as
RadDropDownListElement).Items.Add(
"item1"
);
(editor.EditorElement
as
RadDropDownListElement).Items.Add(
"item2"
);
(editor.EditorElement
as
RadDropDownListElement).Items.Add(
"item3"
);
e.Editor = editor;
}
}
If you want to use visually customized cells, then you can use the CellCreating event to apply your custom cell. Here is a short example:
public
partial
class
Form45 : Form
{
public
static
ListViewDetailColumn checkBoxColumn;
public
Form45()
{
InitializeComponent();
this
.radListView1.CellCreating +=
new
Telerik.WinControls.UI.ListViewCellElementCreatingEventHandler(radListView1_CellCreating);
checkBoxColumn =
this
.radListView1.Columns[2];
}
void
radListView1_CellCreating(
object
sender, Telerik.WinControls.UI.ListViewCellElementCreatingEventArgs e)
{
DetailListViewDataCellElement cellElement = (e.CellElement
as
DetailListViewDataCellElement);
if
(cellElement ==
null
)
{
return
;
}
DetailListViewVisualItem visualItem =
this
.radListView1.ListViewElement.ViewElement.GetElement(cellElement.Row)
as
DetailListViewVisualItem;
if
(visualItem ==
null
)
{
return
;
}
if
(e.CellElement.Data == checkBoxColumn)
{
e.CellElement =
new
CheckBoxCell(
visualItem,
e.CellElement.Data);
}
else
{
e.CellElement =
new
DefaultCell(
visualItem,
e.CellElement.Data);
}
}
}
public
class
CheckBoxCell : DetailListViewDataCellElement
{
private
RadCheckBoxElement checkBox;
public
CheckBoxCell(DetailListViewVisualItem owner, ListViewDetailColumn column)
:
base
(owner, column)
{
}
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
checkBox =
new
RadCheckBoxElement();
checkBox.StretchHorizontally = checkBox.StretchVertically =
true
;
this
.Children.Add(checkBox);
}
public
override
void
Synchronize()
{
base
.Synchronize();
this
.checkBox.Text = (
string
)
this
.Row[
this
.Data];
this
.Text =
""
;
}
public
override
bool
IsCompatible(ListViewDetailColumn data,
object
context)
{
return
Form45.checkBoxColumn == data;
}
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(DetailListViewDataCellElement);
}
}
}
public
class
DefaultCell : DetailListViewDataCellElement
{
public
DefaultCell(DetailListViewVisualItem owner, ListViewDetailColumn column)
:
base
(owner, column)
{
}
public
override
bool
IsCompatible(ListViewDetailColumn data,
object
context)
{
return
Form45.checkBoxColumn != data;
}
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(DetailListViewDataCellElement);
}
}
}
In this case it seems better to use GridView instead, since it provides typed columns which you can use out of the box.
I hope this was helpful. Should you have further questions, do not hesitate to contact me.
Best wishes,
Ivan Todorov
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Javier Gonzalez de Aragon
Top achievements
Rank 2
answered on 09 Nov 2011, 03:59 AM
Hi, I'm using a custom spin editor in one of my ListView Cells. Is there a way to determine if either up or down was clicked?
Thanks,
Javier Gonzalez de Aragon
Thanks,
Javier Gonzalez de Aragon
0
Hello Javier Gonzalez De Aragon,
Thank you for your question.
You can use the following code to subscribe to the events of the up/down buttons:
I hope you find this useful. Feel free to ask if you have any additional questions.
Regards,
Ivan Todorov
the Telerik team
Thank you for your question.
You can use the following code to subscribe to the events of the up/down buttons:
void
radListView1_EditorRequired(
object
sender, Telerik.WinControls.UI.ListViewItemEditorRequiredEventArgs e)
{
ListViewSpinEditor editor =
new
ListViewSpinEditor();
(editor.EditorElement
as
BaseSpinEditorElement).UpButton.Click +=
new
EventHandler(UpButton_Click);
(editor.EditorElement
as
BaseSpinEditorElement).DownButton.Click +=
new
EventHandler(DownButton_Click);
e.Editor = editor;
}
I hope you find this useful. Feel free to ask if you have any additional questions.
Regards,
Ivan Todorov
the Telerik team
Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.