Custom rendered controls in a DataGrid?

M

Mats-Erik Grundh

Custom rendered controls in a DataGrid?

Is it possible to have a custom control column i a datagrid that render html
(richtext and images) without moving to that column.?

Thanks in advance!
 
J

Jeffrey Tan[MSFT]

Hi Mats,

First, I want to confirm is your datagrid Winform or web form based?

For Winform datagrid, we usually extend the DataGrid child controls through
override the normal DataGridColumnStyle then add customized child controls
instead of TextBox or checkbox. There is a complete sample can be
downloaded at:
http://www.gotdotnet.com/userfiles/markbou/GridCombo.zip
This sample project nests ComboBox in the datagrid.

"Tailor Your DataGrid Apps Using Table Style and Custom Column Style
Objects"
http://msdn.microsoft.com/msdnmag/issues/03/08/datagrids/

For Web Form, we may use create a TemplateColumn in DataGrid, then add any
control we wanted to the ItemTemplate.

=============================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
M

Mats-Erik Grundh

Thank You Jeffrey!

My question is about Winforms datagrid.

Your nice samples shows how to replace a column to a custom control when you
focus that column(cell) but i want to render (paint) custom columns without
focus a column or cell, like the following sample:

Row 1 Column one is rich formatted text. Bold and normal. Row 1 Column
two is also rich formatted text. Italic, bold and normal.
Row 2 Some rich formatted text. Row 2 some rich formatted text.
 
J

Jeffrey Tan

Hi Mats,

Thanks very much for your feedback!

Based on my understanding, you want to add customized control to the normal
cell of DataGrid, not only the current cell in edit mode.

I think your requirement is somewhat like DataGridBoolColumnStyle, which
always show a checkbox in each cell in that column. But I will tell you
that, actually, these checkboxes in the normal cell is not a "true"
checkbox. DataGrid only paints a checkbox image to that cell. There is not
an actual checkbox in that cell.

So ,there is no build-in way to get this done. What we can do is simulate
the DataGridBoolColumnStyle, that is: override DataGridColumnStyle.Paint
method, just draw a control like image to each cell.(Because when every row
cell in a column need to be paint, Paint will be called).

However, painting the richtext content is not an easier job. So I suggest
you change your design to use the standard option, only add the RichTextBox
in current editing mode cell, actually, this is the offical supported way
for DataGridColumnStyle.
=============================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
M

Mats-Erik Grundh

Hi Jeffrey,

I was expecting that answer, but i had a little hope of that some magic
trick would solve my problem.

Thank You for Your Help!
 
J

Jeffrey Tan[MSFT]

You are welcome!! If you need further help, please feel free to tell me, I
will help you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top