Hi!
VERSION: 2010 Q2 SP2
This is my simple application:
EditableCheckBoxCellElement:
namespace
GridViewUnboundMode
{
public
class
EditableCheckBoxCellElement : GridDataCellElement
{
private
RadCheckBoxElement _chk;
private
RadTextBoxElement _txtBox;
private
CellValue _cellValue;
public
EditableCheckBoxCellElement(GridViewColumn column, GridRowElement row)
:
base
(column, row)
{
}
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
_chk =
new
RadCheckBoxElement();
_chk.Margin =
new
Padding(2, 2, 2, 2);
_chk.MinSize =
new
Size(10, 10);
_chk.Text =
string
.Empty;
_chk.ToggleState = Telerik.WinControls.Enumerations.ToggleState.Off;
_chk.ToggleStateChanged +=
new
StateChangedEventHandler(_chk_ToggleStateChanged);
_txtBox =
new
RadTextBoxElement();
_txtBox.Margin =
new
Padding(2, 2, 2, 2);
_txtBox.MinSize =
new
Size(10, 10);
_txtBox.Text =
"sss"
;
this
.Children.Add(_chk);
this
.Children.Add(_txtBox);
}
void
_chk_ToggleStateChanged(
object
sender, StateChangedEventArgs args)
{
if
(_chk.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
{ _cellValue.IsAssigned =
true
; }
else
if
(_chk.ToggleState == Telerik.WinControls.Enumerations.ToggleState.Off)
{ _cellValue.IsAssigned =
false
; }
}
protected
override
SizeF ArrangeOverride(SizeF finalSize)
{
if
(
this
.Children.Count == 2)
{
this
.Children[0].Arrange(
new
RectangleF(2, 2, 10, 10));
this
.Children[1].Arrange(
new
RectangleF(21, 2, finalSize.Width - 28 - 10, 15));
}
return
finalSize;
}
public
override
object
Value
{
get
{
return
_cellValue; }
set
{
_cellValue = value
as
CellValue;
if
(_cellValue !=
null
)
{
_txtBox.Text = _cellValue.Text;
this
.IsChecked = _cellValue.IsAssigned;
}
}
}
public
bool
IsChecked
{
get
{
return
_cellValue.IsAssigned;
}
set
{
if
(value)
{ _chk.ToggleState = Telerik.WinControls.Enumerations.ToggleState.On; }
else
{ _chk.ToggleState = Telerik.WinControls.Enumerations.ToggleState.Off; }
_cellValue.IsAssigned = value;
}
}
}
}
EditableCheckBoxColumn:
namespace
GridViewUnboundMode
{
public
class
EditableCheckBoxColumn : GridViewDataColumn
{
public
EditableCheckBoxColumn():
base
()
{
}
public
override
Type GetCellType(GridViewRowInfo row)
{
if
(row
is
GridViewDataRowInfo)
{
return
typeof
(EditableCheckBoxCellElement);
}
return
base
.GetCellType(row);
}
}
}
CellValue:
namespace
GridViewUnboundMode
{
public
class
CellValue
{
public
string
Text {
get
;
set
; }
public
bool
IsAssigned {
get
;
set
; }
}
}
Form1:
namespace
GridViewUnboundMode
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
radGridView1.MultiSelect =
true
;
radGridView1.AllowColumnChooser =
false
;
GridViewDataColumn columnCSname =
new
GridViewTextBoxColumn();
columnCSname.HeaderText =
"Standard column"
;
radGridView1.Columns.Add(columnCSname);
columnCSname.Width = 160;
columnCSname.ReadOnly =
true
;
this
.AddCustomColumns(4);
this
.AddNewRow();
this
.AddNewRow();
columnCSname.IsPinned =
true
;
}
private
void
AddNewRow()
{
GridViewRowInfo rowInfo =
this
.radGridView1.Rows.AddNew();
int
columnIndex = 0;
foreach
(GridViewCellInfo cellInfo
in
rowInfo.Cells)
{
if
(cellInfo.ColumnInfo.Index == 0)
{
cellInfo.Value =
string
.Format(
"Standard column, Col: {0}, Row: {1}"
, cellInfo.ColumnInfo.Index, rowInfo.Index);
}
else
{
CellValue cellValue =
new
CellValue();
cellValue.Text =
string
.Format(
"Col: {0}, Row: {1}"
, cellInfo.ColumnInfo.Index, rowInfo.Index);
cellInfo.Tag = cellValue;
}
columnIndex++;
}
}
private
void
radGridView1_CellFormatting(
object
sender, CellFormattingEventArgs e)
{
EditableCheckBoxCellElement cellElement = e.CellElement
as
EditableCheckBoxCellElement;
if
(cellElement !=
null
)
{
CellValue val = e.CellElement.RowInfo.Cells[e.CellElement.ColumnIndex].Tag
as
CellValue;
cellElement.Value = val;
}
}
private
void
AddCustomColumns(
int
count)
{
for
(
int
index = 0; index < count; index++)
{
GridViewDataColumn newColumn =
new
EditableCheckBoxColumn();
newColumn.HeaderText =
"Col"
+ (radGridView1.Columns.Count + 1).ToString();
newColumn.Name = newColumn.HeaderText;
newColumn.Width = 120;
if
(radGridView1.Columns.Count == 0)
{ newColumn.IsPinned =
true
; }
radGridView1.Columns.Add(newColumn);
}
}
}
}
When I run application I see form from attachment viewAfterStartup.JPG. “Standard column” is pinned at left.
FIRST PROBLEM
If I resize window to smaller size then I have scroll bar on the bottom.
When I start scrolling to right I have problem with text box from custom cells – it overlaps on “Standard column”. This is weird because this problem is only for text box, for check box it is ok (check box does not overlap pinned column) – please check attachments “scrollingCheckBox-OK.JPG” and “scrollingTextBox-NOTok.JPG”. What is wrong in my source code?
SECOND PROBLEM
When I unpin “Standard column” I see in this column cells of class EditableCheckBoxCellElement. How it is possible? Name of column is correct but cells change type. Check attachment “unpinnedFirstColumn.JPG”.
Regards
GridViewTemplate template =
new
GridViewTemplate();
template.AllowColumnResize =
true
;
foreach
(GridViewColumn col
in
myGrid.Columns)
template.Columns.Add((GridViewDataColumn)col);
GridViewInfo info =
new
GridViewInfo(template);
GridViewRowInfo row =
new
GridViewRowInfo(info);
row.AllowResize =
true
;
// oRow contains the values for the cells
for
(
int
i = 0; i < oRow.Length; i++)
row.Cells[i].Value = oRow[i];
row.Tag = epropSample;