Hi Cat,
Ok, I've come up with a workaround so the details column can be the last one. I've re-posted all the changed files here again. It also now includes specifying the columns.
The workaround for getting the details column to be the last (or any other) column is in GridViewRowDetailsExtended
Designer File
partial
class
Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private
System.ComponentModel.IContainer components;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected
override
void
Dispose(
bool
disposing)
{
if
(disposing && (components !=
null
))
{
components.Dispose();
}
base
.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private
void
InitializeComponent()
{
this
.ButtonPopulateHierarchy =
new
Telerik.WinControls.UI.RadButton();
this
.ButtonPopulateRowDetails =
new
Telerik.WinControls.UI.RadButton();
this
.gridViewRowDetailsExtended1 =
new
GridviewRowDetailsExtended.GridViewRowDetailsExtended();
((System.ComponentModel.ISupportInitialize)(
this
.ButtonPopulateHierarchy)).BeginInit();
((System.ComponentModel.ISupportInitialize)(
this
.ButtonPopulateRowDetails)).BeginInit();
((System.ComponentModel.ISupportInitialize)(
this
.gridViewRowDetailsExtended1)).BeginInit();
this
.SuspendLayout();
//
// ButtonPopulateHierarchy
//
this
.ButtonPopulateHierarchy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this
.ButtonPopulateHierarchy.Location =
new
System.Drawing.Point(12, 480);
this
.ButtonPopulateHierarchy.Name =
"ButtonPopulateHierarchy"
;
this
.ButtonPopulateHierarchy.Size =
new
System.Drawing.Size(177, 24);
this
.ButtonPopulateHierarchy.TabIndex = 1;
this
.ButtonPopulateHierarchy.Text =
"Populate With Hierarchy Data"
;
this
.ButtonPopulateHierarchy.Click +=
new
System.EventHandler(
this
.ButtonPopulateHierarchy_Click);
//
// ButtonPopulateRowDetails
//
this
.ButtonPopulateRowDetails.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this
.ButtonPopulateRowDetails.Location =
new
System.Drawing.Point(204, 480);
this
.ButtonPopulateRowDetails.Name =
"ButtonPopulateRowDetails"
;
this
.ButtonPopulateRowDetails.Size =
new
System.Drawing.Size(177, 24);
this
.ButtonPopulateRowDetails.TabIndex = 2;
this
.ButtonPopulateRowDetails.Text =
"Populate With Row Details Data"
;
this
.ButtonPopulateRowDetails.Click +=
new
System.EventHandler(
this
.ButtonPopulateRowDetails_Click);
//
// gridViewRowDetailsExtended1
//
this
.gridViewRowDetailsExtended1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this
.gridViewRowDetailsExtended1.DetailsColumn =
null
;
this
.gridViewRowDetailsExtended1.Location =
new
System.Drawing.Point(12, 12);
this
.gridViewRowDetailsExtended1.Name =
"gridViewRowDetailsExtended1"
;
this
.gridViewRowDetailsExtended1.Size =
new
System.Drawing.Size(522, 453);
this
.gridViewRowDetailsExtended1.TabIndex = 0;
this
.gridViewRowDetailsExtended1.Text =
"gridViewRowDetailsExtended1"
;
this
.gridViewRowDetailsExtended1.CellFormatting +=
new
Telerik.WinControls.UI.CellFormattingEventHandler(
this
.gridViewRowDetailsExtended1_CellFormatting);
//
// Form1
//
this
.AutoScaleDimensions =
new
System.Drawing.SizeF(6F, 13F);
this
.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this
.ClientSize =
new
System.Drawing.Size(543, 516);
this
.Controls.Add(
this
.ButtonPopulateRowDetails);
this
.Controls.Add(
this
.ButtonPopulateHierarchy);
this
.Controls.Add(
this
.gridViewRowDetailsExtended1);
this
.Name =
"Form1"
;
this
.Text =
"Form1"
;
((System.ComponentModel.ISupportInitialize)(
this
.ButtonPopulateHierarchy)).EndInit();
((System.ComponentModel.ISupportInitialize)(
this
.ButtonPopulateRowDetails)).EndInit();
((System.ComponentModel.ISupportInitialize)(
this
.gridViewRowDetailsExtended1)).EndInit();
this
.ResumeLayout(
false
);
}
#endregion
private
GridviewRowDetailsExtended.GridViewRowDetailsExtended gridViewRowDetailsExtended1;
private
Telerik.WinControls.UI.RadButton ButtonPopulateHierarchy;
private
Telerik.WinControls.UI.RadButton ButtonPopulateRowDetails;
}
Form1.cs
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
Telerik.WinControls.UI;
public
partial
class
Form1 : Form
{
BindingList<Person> people =
new
BindingList<Person>();
BindingList<Child> children =
new
BindingList<Child>();
public
Form1()
{
InitializeComponent();
// set defaults
this
.gridViewRowDetailsExtended1.ReadOnly =
true
;
this
.gridViewRowDetailsExtended1.ShowFilteringRow =
false
;
this
.gridViewRowDetailsExtended1.ShowGroupPanel =
false
;
this
.gridViewRowDetailsExtended1.AutoGenerateColumns =
false
;
}
private
void
ButtonPopulateHierarchy_Click(
object
sender, EventArgs e)
{
// reset grid
this
.gridViewRowDetailsExtended1.DataSource =
null
;
this
.gridViewRowDetailsExtended1.Columns.Clear();
PopulatePeople();
PopulateChildren();
GridViewDecimalColumn idColumn =
new
GridViewDecimalColumn(
"Id"
);
idColumn.HeaderText =
"Id"
;
idColumn.Name =
"Id"
;
GridViewTextBoxColumn nameColumn =
new
GridViewTextBoxColumn(
"Name"
);
nameColumn.HeaderText =
"Name"
;
nameColumn.Name =
"Name"
;
GridViewTextBoxColumn titleColumn =
new
GridViewTextBoxColumn(
"Title"
);
titleColumn.HeaderText =
"Title"
;
titleColumn.Name =
"Title"
;
GridViewDateTimeColumn dateColumn =
new
GridViewDateTimeColumn(
"Date"
);
dateColumn.HeaderText =
"Date"
;
dateColumn.Name =
"Date"
;
GridViewTextBoxColumn detailsColumn =
new
GridViewTextBoxColumn(
"Details"
);
detailsColumn.HeaderText =
"Details"
;
detailsColumn.Name =
"Details"
;
GridViewTextBoxColumn commentsColumn =
new
GridViewTextBoxColumn(
"Comments"
);
commentsColumn.HeaderText =
"Comments"
;
commentsColumn.Name =
"Comments"
;
this
.gridViewRowDetailsExtended1.Columns.AddRange(idColumn, nameColumn, titleColumn, dateColumn, commentsColumn, detailsColumn);
// give a data source
this
.gridViewRowDetailsExtended1.DataSource = people;
this
.gridViewRowDetailsExtended1.Columns[
"Details"
].IsVisible =
true
;
// new: use row details false
this
.gridViewRowDetailsExtended1.UseRowDetails =
false
;
this
.gridViewRowDetailsExtended1.ShowRowDetails =
false
;
this
.gridViewRowDetailsExtended1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
// hierarchy stuff - the child template
GridViewTemplate childTemplate =
new
GridViewTemplate();
childTemplate.DataSource = children;
this
.gridViewRowDetailsExtended1.MasterTemplate.Templates.Add(childTemplate);
// set up a relation
GridViewRelation relation =
new
GridViewRelation(
this
.gridViewRowDetailsExtended1.MasterTemplate, childTemplate);
relation.RelationName =
"ParentChildRelation"
;
relation.ParentColumnNames.Add(
"Id"
);
relation.ChildColumnNames.Add(
"ParentId"
);
this
.gridViewRowDetailsExtended1.Relations.Add(relation);
// best fit the columns
foreach
(GridViewDataColumn column
in
this
.gridViewRowDetailsExtended1.Columns)
{ column.BestFit(); }
}
private
void
ButtonPopulateRowDetails_Click(
object
sender, EventArgs e)
{
// reset grid
this
.gridViewRowDetailsExtended1.Relations.Clear();
this
.gridViewRowDetailsExtended1.Templates.Clear();
this
.gridViewRowDetailsExtended1.Columns.Clear();
this
.gridViewRowDetailsExtended1.DataSource =
null
;
PopulatePeople();
GridViewDecimalColumn idColumn =
new
GridViewDecimalColumn(
"Id"
);
idColumn.HeaderText =
"Id"
;
idColumn.Name =
"Id"
;
GridViewTextBoxColumn nameColumn =
new
GridViewTextBoxColumn(
"Name"
);
nameColumn.HeaderText =
"Name"
;
nameColumn.Name =
"Name"
;
GridViewTextBoxColumn titleColumn =
new
GridViewTextBoxColumn(
"Title"
);
titleColumn.HeaderText =
"Title"
;
titleColumn.Name =
"Title"
;
GridViewDateTimeColumn dateColumn =
new
GridViewDateTimeColumn(
"Date"
);
dateColumn.HeaderText =
"Date"
;
dateColumn.Name =
"Date"
;
GridViewTextBoxColumn detailsColumn =
new
GridViewTextBoxColumn(
"Details"
);
detailsColumn.HeaderText =
"Details"
;
detailsColumn.Name =
"Details"
;
GridViewTextBoxColumn commentsColumn =
new
GridViewTextBoxColumn(
"Comments"
);
commentsColumn.HeaderText =
"Comments"
;
commentsColumn.Name =
"Comments"
;
this
.gridViewRowDetailsExtended1.Columns.AddRange(idColumn, nameColumn, titleColumn, dateColumn, commentsColumn, detailsColumn);
// new: use row details true
this
.gridViewRowDetailsExtended1.UseRowDetails =
true
;
this
.gridViewRowDetailsExtended1.Columns[
"Details"
].IsVisible =
false
;
// give it the row details column
this
.gridViewRowDetailsExtended1.DetailsColumn =
this
.gridViewRowDetailsExtended1.Columns[
"Details"
];
// show the row details
this
.gridViewRowDetailsExtended1.EnableAllExpand =
false
;
this
.gridViewRowDetailsExtended1.ShowRowDetails =
true
;
this
.gridViewRowDetailsExtended1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
// so we can add html to the row details area
this
.gridViewRowDetailsExtended1.Columns[
"Details"
].DisableHTMLRendering =
false
;
// data source
this
.gridViewRowDetailsExtended1.DataSource = people;
// best fit the columns
foreach
(GridViewDataColumn column
in
this
.gridViewRowDetailsExtended1.Columns)
{
if
(column.Name !=
"Details"
)
{column.BestFit(); }
}
}
private
void
PopulatePeople()
{
people.Clear();
people.Add(
new
Person(1,
"Richard"
,
"Mr"
, DateTime.Now,
"WinForms Developer"
,
"Here are some details about Richard"
));
people.Add(
new
Person(2,
"Chris"
,
"Mr"
, DateTime.Now,
"Operations Manager"
,
"Here are some details about Chris"
));
people.Add(
new
Person(3,
"Leisl"
,
"Mrs"
, DateTime.Now,
"Administative Assistant"
,
"Here are some details about Leisl"
));
people.Add(
new
Person(4,
"Chris"
,
"Mr"
, DateTime.Now,
"Cleaner"
,
"Here are some details about Chris"
));
people.Add(
new
Person(5,
"Peter"
,
"Mr"
, DateTime.Now,
"WinForms Developer"
,
"Here are some details about Peter"
));
people.Add(
new
Person(6,
"Ester"
,
"Miss"
, DateTime.Now,
"School Teacher"
,
"Here are some details about Ester"
));
}
private
void
PopulateChildren()
{
children.Clear();
children.Add(
new
Child(1, 1,
"Javier"
));
children.Add(
new
Child(2, 2,
"Jamie"
));
children.Add(
new
Child(3, 2,
"Max"
));
children.Add(
new
Child(4, 5,
"Zack"
));
}
private
void
gridViewRowDetailsExtended1_CellFormatting(
object
sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
// if it's a row details grid
if
(
this
.gridViewRowDetailsExtended1.Relations.Count == 0)
{
// and if its the current row and rowDetails column
if
(e.CellElement.RowInfo.IsCurrent && e.CellElement.ColumnInfo ==
this
.gridViewRowDetailsExtended1.DetailsColumn)
{
// set some html and style
e.CellElement.DrawFill =
true
;
e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
e.CellElement.BackColor = Color.LightBlue;
e.CellElement.Padding =
new
Padding(10);
e.CellElement.Text =
"<html>"
+ e.CellElement.Text.Replace(
"Here"
,
"<strong>Here</strong>"
) +
"</html>"
;
}
else
{
// otherwise reset for UI Virtualization
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.PaddingProperty, Telerik.WinControls.ValueResetFlags.Local);
}
}
}
}
/// <summary>
/// Note: Currently, whatever you use for Row Details
/// cannot be the last column. In this case "Details" is one but last
/// </summary>
public
class
Person
{
public
Person(
int
id,
string
name,
string
title, DateTime date,
string
comments,
string
details)
{
this
.Id = id;
this
.Name = name;
this
.Title = title;
this
.Date = date;
this
.Comments = comments;
this
.Details = details;
}
public
int
Id
{
get
;
set
; }
public
string
Name
{
get
;
set
;}
public
string
Title
{
get
;
set
;}
public
DateTime Date
{
get
;
set
;}
public
string
Details
{
get
;
set
; }
public
string
Comments
{
get
;
set
;}
}
public
class
Child
{
public
Child(
int
id,
int
parentId,
string
name)
{
this
.Id = id;
this
.ParentId = parentId;
this
.Name = name;
}
public
int
Id
{
get
;
set
; }
public
int
ParentId
{
get
;
set
; }
public
string
Name
{
get
;
set
; }
}
GridViewRowDetailsExtended.cs
using
System;
using
System.Collections.Generic;
using
System.Text;
using
Telerik.WinControls.UI;
using
System.ComponentModel;
namespace
GridviewRowDetailsExtended
{
public
class
GridViewRowDetailsExtended : RadGridView
{
private
GridViewDataColumn renamedDetailsColumn;
private
int
renamedDetailsRowHeight = 100;
private
bool
showRowDetails =
true
;
private
bool
enableAllExpand =
true
;
private
bool
useRowDetails =
true
;
public
GridViewRowDetailsExtended()
{
this
.GridBehavior =
new
RowDetailsBehavior();
this
.ViewDefinition =
new
RowDetailsViewDefinition();
}
public
override
string
ThemeClassName
{
get
{
return
typeof
(RadGridView).FullName; }
set
{ }
}
public
bool
UseRowDetails
{
get
{
return
useRowDetails; }
set
{ useRowDetails = value; }
}
[Browsable(
false
)]
[Category(
"Row Details"
)]
public
GridViewDataColumn DetailsColumn
{
get
{
return
this
.renamedDetailsColumn; }
set
{
if
(!
object
.ReferenceEquals(renamedDetailsColumn, value))
{
if
(useRowDetails ==
true
)
{
renamedDetailsColumn = value;
if
(renamedDetailsColumn !=
null
)
{
renamedDetailsColumn.MinWidth = 0;
renamedDetailsColumn.HeaderText =
""
;
renamedDetailsColumn.Width = 0;
renamedDetailsColumn.ReadOnly =
true
;
renamedDetailsColumn.VisibleInColumnChooser =
false
;
if
(renamedDetailsColumn.Index !=
this
.ColumnCount - 1)
{renamedDetailsColumn.MaxWidth = 1;}
else
{renamedDetailsColumn.MaxWidth = 2;}
}
this
.TableElement.UpdateView();
}
}
}
}
[Browsable(
true
)]
[Category(
"Row Details"
)]
[DefaultValue(100)]
public
int
DetailsRowHeight
{
get
{
return
this
.renamedDetailsRowHeight;
}
set
{
if
(renamedDetailsRowHeight != value && useRowDetails ==
true
)
{
renamedDetailsRowHeight = value;
TableElement.Update(GridUINotifyAction.Reset);
TableElement.UpdateView();
}
}
}
[Browsable(
true
)]
[Category(
"Row Details"
)]
[DefaultValue(
true
)]
public
bool
ShowRowDetails
{
get
{
return
this
.showRowDetails;
}
set
{
if
(useRowDetails ==
true
)
{
showRowDetails = value;
this
.DetailsColumn.IsVisible = value;
TableElement.Update(GridUINotifyAction.Reset);
TableElement.UpdateView();
}
}
}
[Browsable(
true
)]
[Category(
"Row Details"
)]
[Description(
"Allows all rows to be expanded (true) or only selected row expanded (false)"
)]
[DefaultValue(
true
)]
public
bool
EnableAllExpand
{
get
{
return
this
.enableAllExpand; }
set
{
this
.enableAllExpand = value;
TableElement.Update(GridUINotifyAction.Reset);
TableElement.UpdateView();
}
}
[Browsable(
false
)]
[Category(
"Row Details"
)]
[DefaultValue(
true
)]
public
bool
RowDetailsShowing
{
get
{
return
this
.showRowDetails; }
}
protected
override
void
OnCreateRow(
object
sender, GridViewCreateRowEventArgs e)
{
if
(useRowDetails ==
true
)
{
if
(
object
.ReferenceEquals(e.RowType,
typeof
(GridDataRowElement)))
{
e.RowType =
typeof
(RowDetailsRowElement);
}
}
base
.OnCreateRow(sender, e);
}
}
}
i hope that helps, but if you have any comments or questions, please let me know
Thanks
Richard