Greetings!
I'd love to know if there's a problem with my code or if this is some kind of bug in the GridView, as the result is very strange.
If I create a custom column by inheriting GridViewDataColumn, the cell for that column will appear correctly in its own column, but will also occasionally appear in other columns.
Steps to reproduce
This is not my actual implementation, but a much simplified bit of code that reproduces the problem - the custom column here just displays a button for testing purposes.
I am running Telerik Controls for Windows Forms 2010.3.10.1215
Create a form called "ManualBuildTest" with a RadGridView on it, called "Grid" (Dock: Fill). Then use the following code in the form:
I'd love to know if there's a problem with my code or if this is some kind of bug in the GridView, as the result is very strange.
If I create a custom column by inheriting GridViewDataColumn, the cell for that column will appear correctly in its own column, but will also occasionally appear in other columns.
Steps to reproduce
This is not my actual implementation, but a much simplified bit of code that reproduces the problem - the custom column here just displays a button for testing purposes.
I am running Telerik Controls for Windows Forms 2010.3.10.1215
Create a form called "ManualBuildTest" with a RadGridView on it, called "Grid" (Dock: Fill). Then use the following code in the form:
public
partial
class
ManualBuildTest : Form
{
public
ManualBuildTest()
{
InitializeComponent();
}
private
void
ManualBuildTest_Load(
object
sender, EventArgs e)
{
var col1 =
new
DataLinkColumn(
string
.Empty);
col1.AllowGroup =
true
;
col1.HeaderText =
"Requested By"
;
Grid.Columns.Add(col1);
var col =
new
GridViewTextBoxColumn();
col.AllowGroup =
true
;
col.ReadOnly =
false
;
col.HeaderText =
"Position"
;
Grid.Columns.Add(col);
col =
new
GridViewTextBoxColumn();
col.AllowGroup =
true
;
col.ReadOnly =
false
;
col.HeaderText =
"Organisation"
;
Grid.Columns.Add(col);
col =
new
GridViewTextBoxColumn();
col.AllowGroup =
false
;
col.ReadOnly =
false
;
col.HeaderText =
"Work Phone"
;
Grid.Columns.Add(col);
col =
new
GridViewTextBoxColumn();
col.AllowGroup =
false
;
col.ReadOnly =
false
;
col.HeaderText =
"Mobile"
;
Grid.Columns.Add(col);
col =
new
GridViewTextBoxColumn();
col.AllowGroup =
false
;
col.ReadOnly =
false
;
col.HeaderText =
"E-Mail"
;
Grid.Columns.Add(col);
col =
new
GridViewTextBoxColumn();
col.AllowGroup =
false
;
col.ReadOnly =
false
;
col.HeaderText =
"Fax"
;
Grid.Columns.Add(col);
var dcol =
new
GridViewDateTimeColumn();
dcol.AllowGroup =
true
;
dcol.ReadOnly =
false
;
dcol.HeaderText =
"Date Requested"
;
Grid.Columns.Add(dcol);
col =
new
GridViewTextBoxColumn();
col.AllowGroup =
true
;
col.ReadOnly =
false
;
col.HeaderText =
"Request"
;
Grid.Columns.Add(col);
col =
new
GridViewTextBoxColumn();
col.AllowGroup =
true
;
col.ReadOnly =
false
;
col.HeaderText =
"Status"
;
Grid.Columns.Add(col);
col =
new
GridViewTextBoxColumn();
col.AllowGroup =
true
;
col.ReadOnly =
false
;
col.HeaderText =
"Assigned To"
;
Grid.Columns.Add(col);
dcol =
new
GridViewDateTimeColumn();
dcol.AllowGroup =
true
;
dcol.ReadOnly =
false
;
dcol.HeaderText =
"Request Completed"
;
Grid.Columns.Add(dcol);
col =
new
GridViewTextBoxColumn();
col.AllowGroup =
true
;
col.ReadOnly =
false
;
col.HeaderText =
"Result of Request"
;
Grid.Columns.Add(col);
Grid.Rows.AddNew();
Grid.Rows.AddNew();
}
}
public
class
DataLinkColumn : GridViewDataColumn
{
public
DataLinkColumn(
string
fieldName)
:
base
(fieldName)
{
}
public
override
Type GetCellType(GridViewRowInfo row)
{
if
(row
is
GridViewDataRowInfo)
return
typeof
(DataLinkCellElement);
return
base
.GetCellType(row);
}
}
public
class
DataLinkCellElement : GridDataCellElement
{
private
RadButtonElement _ctlButton;
public
DataLinkCellElement(GridViewColumn column, GridRowElement row)
:
base
(column, row)
{
}
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
_ctlButton =
new
RadButtonElement();
_ctlButton.Text =
"TEST"
;
_ctlButton.ShowBorder =
true
;
Children.Add(_ctlButton);
}
protected
override
void
SetContentCore(
object
value)
{
_ctlButton.Text = value ==
null
?
"(null)"
: value.ToString();
}
}
If you then run the form, everything (usually) looks fine at first: the custom column appears in the first column as set (the cell contains a button with the word "(null)" in it for now).
But if you make sure that the window is small enough that the Grid's horizontal scrollbar appears, and scroll back and forth, the custom button is appearing in other cells sporadically (see the attachment for an example).
I've tried to match my code to existing code examples, and even tried it with the RadRadioButtonCellElement custom column from the Knowledge Base, and got the same result.
Is there something fundamentally wrong with my code?
FRASER TUSTIAN