
I have a BindingList of a business object that I want to bind with a ListView (in detail mode).
I can change which properties get displayed (and there respective column headers) using the ColumnCreating event, but I cannot change the order of the columns.
As I understand, the binding process of ListView will use the properties in the order that they appear in code, this should have been fine, except that in case of object inheritance, the parent's class properties come after the child's class properties. In my case, I want base class properties to appear first and followed by child class properties.
Is there a way to change or affect the order that columns get created?
This would also allow me to save and recreate the order in which the columns appear, if, in future, I allow the user to reorder the columns of the ListView.
I know that I could use a DataTable to manipulate the columns beforehand, and use this as my binding source, but I would like to avoid this "conversion" between business object and DataTable.
5 Answers, 1 is accepted
Thank you for writing.
You can reorder the columns programmatically after setting the DataSource property by using the RadListView.Columns.Move method. It is necessary to pass the old column index and the new one. Here is a sample code snippet:
public
Form1()
{
InitializeComponent();
BindingList<B> items =
new
BindingList<B>();
for
(
int
i = 0; i < 5; i++)
{
items.Add(
new
B(i,
"Item"
+ i,
"Info"
+ i, i % 2 == 0));
}
this
.radListView1.DataSource = items;
this
.radListView1.ViewType = Telerik.WinControls.UI.ListViewType.DetailsView;
this
.radListView1.Columns.Move(2, 0);
this
.radListView1.Columns.Move(3, 1);
}
public
class
A
{
public
int
Id {
get
;
set
; }
public
string
Name {
get
;
set
; }
public
A(
int
id,
string
name)
{
this
.Id = id;
this
.Name = name;
}
}
public
class
B : A
{
public
string
Info {
get
;
set
; }
public
bool
IsActive {
get
;
set
; }
public
B(
int
id,
string
name,
string
info,
bool
isActive)
:
base
(id, name)
{
this
.Info = info;
this
.IsActive = isActive;
}
}
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik by Progress

Thank you, missed that :)
Used the BindingCompleted event of listview to start the process of rearranging the columns.
.jpg)
Thank you for writing.
Note that you can iterate the RadListView.Columns collection and find the desired column. Then, you can extract its index by using the Columns.IndexOf passing the ListViewDetailColumn. Here is demonstrated a sample code snippet:
foreach
(ListViewDetailColumn column
in
this
.radListView1.Columns)
{
if
(column.Name==
"IsActive"
)
{
int
columnIndex =
this
.radListView1.Columns.IndexOf(column);
}
}
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Progress Telerik
.jpg)