How to put different cell type in the same DataGrid column?

J

Jeffrey Tan[MSFT]

Hi Sharon,

Thanks for your post!

In non-editing mode, DataGrid does not display the real controls, the
DataGridColumnStyle paints the cell contents internally. So when you are
using DataGridBoolColumn, the checkboxes in that column are not the real
checkboxes, DataGridBoolColumn.Paint method draws the dummy CheckBoxes. You
may use Reflector to view DataGridBoolColumn.Paint method source code to
verify this.

Whenever the end user clicked certain cell in DataGrid, the DataGrid will
invoke corresponding DataGridColumnStyle's Edit method. Normally, this
method will show an internal Control and move to that cell rectangle. In
non-editing mode, that editing control is in invisible state. Please refer
to DataGridTextBoxColumn.Edit method with Reflector to see the code.

With these background information, you can see that DataGridColumnStyle
will host an invisible control in initialization time, while shows it out
in editing time. Conceptually, what you want can be achieved with
customized code. You may inherit from DataGridColumnStyle and create
several controls in the constructor, then in Edit method, you may show out
you wanted control regarding the editing row number. Also, you have to
decide what control appearance to draw in the Paint method. There are still
some that issues to consider, for example, commit the control editing value
to the datasource etc... This is a not easy work to be done.

Currently, I can not find any sample regarding your requirement. If you
want to implement it, you may refer to the 2 articles below for a sample.
These 2 articles both demonstrates hosting one control in the column, you
may extend with customized code following the logic I decribed above:
"Columns With Style"
http://www.i-syn.gmxhome.de/devcom/colstyles/intro.htm
"5.9 How can I put a combobox in a column of a datagrid?"
http://64.78.52.104/FAQ/WinForms/FAQ_c44c.asp#q480q

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Sharon,

Does my reply make sense to you? If you have any concern, please feel free
to tell me, thanks!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
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