Hi,
I am binding a datatable and there is one column of bit datatype. Now system automatically replace bit column with a checkbox, but I want to replace those checkboxes with my custom text.
Can we have some event on that I can change things in particular cell. Or there is some specific way to do so !
Thanks,
With Regards,
Divyesh
I am binding a datatable and there is one column of bit datatype. Now system automatically replace bit column with a checkbox, but I want to replace those checkboxes with my custom text.
Can we have some event on that I can change things in particular cell. Or there is some specific way to do so !
Thanks,
With Regards,
Divyesh
4 Answers, 1 is accepted
0
Hello Divyesh Chapaneri,
Thank you for writing.
If you would like to display text instead of checkboxes, you should change the CellElement type. You can do that in the handler of the CreateCell event. Further, you can set your own text in the CellFormating event. I have demonstrated the approach in the sample project attached.
If you have additional questions, feel free to contact me.
Best wishes,
Nikolay
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Thank you for writing.
If you would like to display text instead of checkboxes, you should change the CellElement type. You can do that in the handler of the CreateCell event. Further, you can set your own text in the CellFormating event. I have demonstrated the approach in the sample project attached.
If you have additional questions, feel free to contact me.
Best wishes,
Nikolay
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Joel Kraft
Top achievements
Rank 2
answered on 23 Oct 2008, 08:53 PM
I'm doing the exact same thing and it's working beautifully except for one small hitch. In the custom-typed cells, I get the word "true" or "false" in the cell along with the custom text I set in the CellFormatting event. I have a screenshot but don't see how to attach it.
Here's my custom type:
Here's my custom type:
public class PseudoCheckBoxCellElement : GridDataCellElement |
{ |
public static readonly string UncheckedString = "£"; |
public static readonly string CheckedString = "T"; |
public PseudoCheckBoxCellElement(GridViewColumn column, GridRowElement row) |
: base(column, row) |
{ |
} |
protected override void CreateChildElements() |
{ |
base.CreateChildElements(); |
StackLayoutPanel panel = new StackLayoutPanel(); |
panel.Alignment = ContentAlignment.MiddleCenter; |
panel.StretchHorizontally = false; |
panel.StretchVertically = false; |
this.Children.Add(panel); |
TextPrimitive text = new TextPrimitive(); |
text.Font = new Font("Wingdings 2", 9F); |
panel.Children.Add(text); |
} |
} |
And the cell events:
private void gvAvailablePackages_CreateCell(object sender, GridViewCreateCellEventArgs e) |
{ |
/// Since GridViewCheckBoxColumn is a pain, replace all of them with PseudoCheckBoxCellElement |
if (e.Column is GridViewCheckBoxColumn) |
e.CellType = typeof(PseudoCheckBoxCellElement); |
} |
private void gvAvailablePackages_CellFormatting(object sender, CellFormattingEventArgs e) |
{ |
if (e.CellElement.ColumnIndex == 1) // if it's the checkbox column |
{ |
// replace the text with an un/checked glyph |
((TextPrimitive)e.CellElement.Children[0].Children[0]).Text = |
((((Package)e.CellElement.RowInfo.DataBoundItem).IsChecked) ? |
PseudoCheckBoxCellElement.CheckedString : PseudoCheckBoxCellElement.UncheckedString); |
} |
} |
0
Hello Joel Kraft,
Thank you for contacting us.
The reason why you see both texts overlapping each other is because there is still a text for the CellElement itself. So, what you should do is setting the text directly to the CellElement instead of its TextPrimitive:
I am attaching a sample project to demonstrate this.
As to the file attachments, they are allowed only in our support ticketing system. Therefore, when you need to attach files, please open a new support ticket.
I hope this helps. If you have additional questions, feel free to contact me.
Kind regards,
Nikolay
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Thank you for contacting us.
The reason why you see both texts overlapping each other is because there is still a text for the CellElement itself. So, what you should do is setting the text directly to the CellElement instead of its TextPrimitive:
private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) |
{ |
if (e.CellElement.ColumnIndex == 4) |
{ |
e.CellElement.Text = |
(((bool)((GridDataCellElement)e.CellElement).Value) ? |
PseudoCheckBoxCellElement.CheckedString : PseudoCheckBoxCellElement.UncheckedString); |
} |
} |
I am attaching a sample project to demonstrate this.
As to the file attachments, they are allowed only in our support ticketing system. Therefore, when you need to attach files, please open a new support ticket.
I hope this helps. If you have additional questions, feel free to contact me.
Kind regards,
Nikolay
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Joel Kraft
Top achievements
Rank 2
answered on 28 Oct 2008, 04:22 PM
Thanks!