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

Tech-Archive recommends: Fix windows errors by optimizing your registry



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.

.



Relevant Pages

  • Re: Loading UserForm Controls (with a twist!)
    ... Split the value of the cell into a Variant: ... Loop through the variant and re-populate each control accordingly ... and each Frame contains several CheckBoxes. ... the Cell A1 will contain the Value "Caption 1; ...
    (microsoft.public.excel.programming)
  • Re: Multiple Checkboxes
    ... If you decide that you like the linked cell (it could be nice for counting the ... Excel table and just wanted to put in Multiple Checkboxes. ... Dim cellUnder As Range ... ' Must deactivate clicked control for code to run. ...
    (microsoft.public.excel)
  • Datagrid with web user controls
    ... I have a datagrid consisting of only one column. ... I also like to have checkboxes in the datagrid so that user can select ... What I did - I created user control AlbumChkBox, ...
    (microsoft.public.dotnet.framework.aspnet.datagridcontrol)
  • Re: Datagrid table cells and rows -- Changing width
    ... You don't have full control over column width. ... Then the browser will set the width of this ... Setting cell width for every row separately, as in your example, doesn't ... > I have a datagrid that contains 3 colums. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Display 1 data row as multiple datagrid rows
    ... I have written a custom control before, ... isn't intuitively obvious how to easily extend the Microsoft datagrid to do ... horizontal scrolling is consider bad design. ... wrap too and allow for sorting of any column it's practical to sort on. ...
    (microsoft.public.dotnet.framework.aspnet)