I am using C++/CLI with the Telerik GridView. I have a checkbox column which I wanted to add the CheckBoxHeaderCell class to. (Reference: http://www.telerik.com/support/kb/winforms/gridview/add-check-uncheck-all-check-box-in-the-header-cell.aspx). I wrote the example and compiled it in C++/CLI from the given C# code. However, I do not know how to tell my grid view to USE this class as a columns header cell. Any help would be appreciated!
- John
- John
3 Answers, 1 is accepted
0
Hi John,
Thank you for writing.
I can provide you with help in C# and VB, but not in C++. As you can see in the example project attached in the KB article, after the column class is created, you can simply create an instance of the class and add the instantiated column to the Columns collection of RadGridView:
I hope that you find this information helpful.
Kind regards,
Stefan
the Telerik team
Thank you for writing.
I can provide you with help in C# and VB, but not in C++. As you can see in the example project attached in the KB article, after the column class is created, you can simply create an instance of the class and add the instantiated column to the Columns collection of RadGridView:
CustomCheckBoxColumn checkColumn =
new
CustomCheckBoxColumn();
checkColumn.Name =
"Select"
;
checkColumn.HeaderText =
"All"
;
this
.radGridView1.Columns.Insert(0, checkColumn);
I hope that you find this information helpful.
Kind regards,
Stefan
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
John
Top achievements
Rank 1
answered on 14 Feb 2012, 06:33 PM
For my C++ brethren out there...here is the check box header cell in C++:
public
ref
class
CheckBoxHeaderCell :
public
GridHeaderCellElement
{
public
: CheckBoxHeaderCell(GridViewColumn^ column, GridRowElement^ row) : GridHeaderCellElement(column, row)
{
InitializeComponent();
this
->_suspendProcessingToggleStateChanged =
false
;
this
->_checkbox = gcnew RadCheckBoxElement();
this
->_checkbox->ToggleStateChanged += gcnew StateChangedEventHandler(
this
, &CheckBoxHeaderCell::checkbox_ToggleStateChanged);
this
->Children->Add(
this
->_checkbox);
}
protected
: ~CheckBoxHeaderCell()
{
if
(components)
{
delete
components;
}
}
protected
:
virtual
SizeF ArrangeOverride(SizeF finalSize) override
{
SizeF size =
this
->GridHeaderCellElement::ArrangeOverride(finalSize);
RectangleF^ rect = GetClientRectangle(finalSize);
this
->_checkbox->Arrange(RectangleF((finalSize.Width -
this
->_checkbox->DesiredSize.Width) / 2, (rect->Height - 20) / 2, 20, 20));
return
size;
}
public
:
virtual
bool
IsCompatible(GridViewColumn^ data, System::Object^ context) override
{
return
data->Name ==
"Select"
&& (
dynamic_cast
<GridTableHeaderRowElement^>(context) != nullptr) &&
this
->GridHeaderCellElement::IsCompatible(data, context);
}
protected
:
void
checkbox_ToggleStateChanged(System::Object^ sender, StateChangedEventArgs^ args)
{
if
(!
this
->_suspendProcessingToggleStateChanged)
{
bool
valueState =
false
;
if
(args->ToggleState == Telerik::WinControls::Enumerations::ToggleState::On)
{
valueState =
true
;
}
this
->GridViewElement->EditorManager->EndEdit();
this
->TableElement->BeginUpdate();
for
(auto i = 0; i <
this
->ViewInfo->Rows->Count; i++)
{
this
->ViewInfo->Rows[i]->Cells[
this
->ColumnIndex]->Value = valueState;
}
this
->TableElement->EndUpdate(
false
);
this
->TableElement->Update(GridUINotifyAction::DataChanged);
}
}
public
:
void
SetCheckBoxState(Telerik::WinControls::Enumerations::ToggleState state)
{
this
->_suspendProcessingToggleStateChanged =
true
;
this
->_checkbox->ToggleState = state;
this
->_suspendProcessingToggleStateChanged =
false
;
}
public
:
virtual
void
Attach(GridViewColumn^ data, System::Object^ context) override
{
this
->GridHeaderCellElement::Attach(data, context);
this
->GridControl->ValueChanged += gcnew System::EventHandler(
this
, &CheckBoxHeaderCell::GridControl_ValueChanged);
}
public
:
virtual
void
Detach() override
{
if
(
this
->GridControl != nullptr)
{
this
->GridControl->ValueChanged -= gcnew System::EventHandler(
this
, &CheckBoxHeaderCell::GridControl_ValueChanged);
}
this
->GridHeaderCellElement::Detach();
}
void
GridControl_ValueChanged(System::Object^ sender, EventArgs^ e)
{
RadCheckBoxEditor^ editor =
dynamic_cast
<RadCheckBoxEditor^>(sender);
if
(editor != nullptr)
{
this
->GridViewElement->EditorManager->EndEdit();
if
(
static_cast
<ToggleState>(editor->Value) == ToggleState::Off)
{
SetCheckBoxState(ToggleState::Off);
}
else
if
(
static_cast
<ToggleState>(editor->Value) == ToggleState::On)
{
bool
found =
false
;
for
each(GridViewRowInfo^ row in
this
->ViewInfo->Rows)
{
if
(row !=
this
->RowInfo && row->Cells[
this
->ColumnIndex]->Value == nullptr || !(
bool
)row->Cells[
this
->ColumnIndex]->Value)
{
found =
true
;
break
;
}
}
if
(found ==
false
)
{
SetCheckBoxState(ToggleState::On);
}
}
}
}
private
: RadCheckBoxElement^ _checkbox;
private
:
bool
_suspendProcessingToggleStateChanged;
private
: System::ComponentModel::Container ^components;
#pragma 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>
void
InitializeComponent(
void
)
{
}
#pragma endregion
};
public
ref
class
CustomCheckBoxColumn :
public
GridViewCheckBoxColumn
{
public
:
virtual
System::Type^ GetCellType(GridViewRowInfo^ row) override
{
if
(
dynamic_cast
<GridViewTableHeaderRowInfo^>(row) != nullptr)
{
return
CheckBoxHeaderCell::
typeid
;
}
return
this
->GridViewCheckBoxColumn::GetCellType(row);
}
};
0
Thank you for sharing your code with the community. If you have any other questions, do not hesitate to contact us.
All the best,
Stefan
the Telerik team
All the best,
Stefan
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>