Dear Admins.
Using Telerik Winform UI R2 2019 SP1.
I'm trying to add Custom Cell in gridview column. (want to add 2 Buttons and a TextBox)
What i have did is
public
class
CustomCellElement : GridDataCellElement
{
private
RadButtonElement radButtonElement;
private
RadButtonElement radButtonElement1;
private
RadTextBoxElement radTextBoxElement;
public
CustomCellElement(GridViewColumn column, GridRowElement row) :
base
(column, row)
{
}
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
radButtonElement =
new
RadButtonElement
{
Text =
"-"
,
Margin =
new
Padding(1, 1, 2, 1)
};
radButtonElement.Click +=
new
EventHandler(radButtonElement_Click);
this
.Children.Add(radButtonElement);
this
.radTextBoxElement =
new
RadTextBoxElement
{
Margin =
new
Padding(1, 1, 1, 1),
TextAlign = HorizontalAlignment.Right
};
this
.Children.Add(radTextBoxElement);
radButtonElement1 =
new
RadButtonElement
{
Text =
"+"
,
Margin =
new
Padding(2, 1, 1, 1)
};
radButtonElement1.Click +=
new
EventHandler(radButtonElement1_Click);
this
.Children.Add(radButtonElement1);
}
private
void
radButtonElement_Click(
object
sender, EventArgs e)
{
int
value = Convert.ToInt32(radTextBoxElement.Text) - 1;
if
(value > 0)
radTextBoxElement.Text = Convert.ToString(value);
}
private
void
radButtonElement1_Click(
object
sender, EventArgs e)
{
int
value = Convert.ToInt32(radTextBoxElement.Text) + 1;
if
(value > 0)
radTextBoxElement.Text = Convert.ToString(value);
}
protected
override
void
DisposeManagedResources()
{
radButtonElement.Click -=
new
EventHandler(radButtonElement_Click);
radButtonElement1.Click -=
new
EventHandler(radButtonElement1_Click);
base
.DisposeManagedResources();
}
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(GridDataCellElement);
}
}
protected
override
SizeF ArrangeOverride(SizeF finalSize)
{
if
(
this
.Children.Count == 3)
{
float
textBoxWidth = finalSize.Width - radButtonElement.DesiredSize.Width - radButtonElement1.DesiredSize.Width;
RectangleF buttonRect =
new
RectangleF(0, 0, radButtonElement.DesiredSize.Width, finalSize.Height);
RectangleF textBoxRect =
new
RectangleF(radButtonElement.DesiredSize.Width - 1, 0, textBoxWidth - 1, finalSize.Height);
RectangleF button1Rect =
new
RectangleF(textBoxWidth + radButtonElement.DesiredSize.Width - 1, 0, radButtonElement1.DesiredSize.Width, finalSize.Height);
this
.Children[0].Arrange(buttonRect);
this
.Children[1].Arrange(textBoxRect);
this
.Children[2].Arrange(button1Rect);
}
return
finalSize;
}
}
public
class
CustomColumn : GridViewDataColumn
{
public
CustomColumn() :
base
()
{ }
public
CustomColumn(
string
fieldName) :
base
(fieldName)
{
}
public
CustomColumn(
string
uniqueName,
string
fieldName) :
base
(uniqueName, fieldName)
{
}
public
override
Type GetCellType(GridViewRowInfo row)
{
if
(row
is
GridViewDataRowInfo)
{
return
typeof
(CustomCellElement);
}
return
base
.GetCellType(row);
}
}
I'm Facing Display problem Please see Image.
Buttons are not displaying properly, cutting the sides. TextBox should be according to the height of GridView cell you can see empty area at the bottom.
How to get and set the value of text box. when row is adding directly to grid.
Please note that the Gridview AllowAddNewRow & AllowEditRow is set to False.(adding Row to GridView Programatically)
But I can Still change the value in the Textbox(Editing to textbox should be disabled.)
Apply the format like other column(please see image).