We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Data Template Cell & Multi-Cell Selection

Hi,

I've created my own Data Template Cell to be used in a GridControl,
using your sample DataTemplateCell_2008 as a starter. It works great.

But i cannot do a multi-cell selection (with the mouse or the keyboard) when the starter cell's type is my Data Template cell type.

In your sample, the multi-cell selection works.

Here's my Data Template definition:



Background="{Binding Converter={StaticResource CellDataBarGridBackgroundConvertor}}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch">






Margin="0"
Height="{Binding Mode=OneWay, ElementName=CellDataBarGrid, Path=ActualHeight, Converter={StaticResource CellDataBarHeightConvertor}}"
BorderBrush="{Binding Mode=OneWay, Converter={StaticResource CellDataBarBorderConvertor}}"
HorizontalAlignment="Left" VerticalAlignment="Center"
Background="{Binding Mode=OneWay, Converter={StaticResource CellDataBarBackgroundConvertor}}">







BorderThickness="0" Margin="0" BorderBrush="Transparent"
Width="{Binding ElementName=CellDataBarGrid, Path=ActualWidth}"
Height="{Binding ElementName=CellDataBarGrid, Path=ActualHeight}">
Text="{Binding Mode=OneWay, Converter={StaticResource CellDataBarValueConvertor}}"
Visibility="{Binding Mode=OneWay, Converter={StaticResource CellDataBarValueVisibilityConvertor}}"
VerticalAlignment="{Binding Mode=OneWay, Converter={StaticResource CellDataBarValueVerticalAlignmentConvertor}}"
HorizontalAlignment="{Binding Mode=OneWay, Converter={StaticResource CellDataBarValueHorizontalAlignmentConvertor}}"
TextTrimming="CharacterEllipsis" TextWrapping="NoWrap"
Background="Transparent" Padding="0" Margin="0"/>





Thanks,
P.OM
Reportive SA


15 Replies

MS Mohamed Suhaib Fahad A. Syncfusion Team January 13, 2010 09:37 AM UTC

Hi Puthirak,

Thanks for using Syncfusion products. When defining custom DataTemplate's the mouse behaviors get handled internally with the Template's control, and this would not work with the Mouse behavior architecture of the grid. However, we have an Attached property that you can use to allow Mouse being handled by the base root object (Grid) itself(syncfusion:VisualContainer.WantsMouseInput="true"). In our samples too we have used this to allow mouse behaviors,


syncfusion:VisualContainer.WantsMouseInput="true">

Mode="TwoWay"
UpdateSourceTrigger="PropertyChanged"
>








Let us know if this helps.

Thanks,
Fahad


PO Puthirak OM January 13, 2010 10:17 AM UTC

Hi,

By setting the property on the grid :

syncfusion:VisualContainer.WantsMouseInput="False"

It works.

Thanks,

P.OM
Reportive SA


MS Mohamed Suhaib Fahad A. Syncfusion Team January 14, 2010 05:14 AM UTC

Hi Puthirak,

Thanks for the details. You can update us if you have anything else.

Thanks,
Fahad


JD Jean-Marc DUHEN March 10, 2010 11:03 AM UTC

Hi,

Is there still a problem with multiple selection and datatemplates ?

For example :






.. the multiple selection does not work.

Thank you


GK Ganesan K Syncfusion Team March 17, 2010 08:47 PM UTC

Hi Jean,

We fixed this issue in our latest source. Please create a Direct trac incident to get latest assemblies.

Please let us know if you need any more details.

Thanks
Ganesan


NM Nickolas Muson July 15, 2011 03:41 PM UTC

I know this a long time since this was an active issue, but I have a question: No matter what I do with the grid and the datatemplates, I cannot change the way the cell selection works.

I have tried:
- Grid1.AllowSelection = None, or Cell, or Cell | Multi
- ListBoxSelectionMode="None"
- ListBoxModeAllowUIElementClick="False"
- AutoFocusCurrentItem="False"

and any number of combinations of
- syncfusion:VisualContainer.WantsMouseInput on the DataTemplates.

No matter what I do:
- The whole row gets selected with an orange bg when I select any cell
- The non-DataTemplated cells are a little darker orange when selected
- No multiselection of cells is possible
- The DataTemplated cols (Customer and Freight) cannot be selected without also putting them into edit mode.

My biggest problem right now is that I need to have cols with a CellItemTemplate, but that seems to break selection and multiselection. No matter what I do the cell goes into edit mode.



RA Rajasekar Syncfusion Team July 19, 2011 01:04 PM UTC

Hi Nickolas,

Sorry for the inconvenience caused.

You can perform cell selection by using the below code snippet,

this.dataGrid.ListBoxSelectionMode = GridSelectionMode.None;
this.dataGrid.AllowSelection = GridSelectionFlags.Cell;

For selection behaviour while editing the Datatemplate cells, you can clear the selection by using the below code snippet,

this.dataGrid.CurrentCellStartEditing += new Syncfusion.Windows.ComponentModel.GridCancelRoutedEventHandler(dataGrid_CurrentCellStartEditing);

void dataGrid_CurrentCellStartEditing(object sender, Syncfusion.Windows.ComponentModel.SyncfusionCancelRoutedEventArgs args)
{
this.dataGrid.Model.SelectedRanges.Clear();
}

Sample:

< http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=CS-325583311.zip >

Please let us know if you have any queries.

Thanks,
Rajasekar





NM Nickolas Muson July 20, 2011 05:52 PM UTC

Wow, Rajasekar, I am very impressed with the quick response, and your code sample id excellent, thank you.

However, I did a little test with the sample code and was able to easily reproduce the problem I am still having. All I did was modify Window1.xaml (attached) to add the exact same validatedTextBoxStyle to the ShipCity and ShipCountry columns using the same technique you did on the Freight column (though I removed the rules obviously)

So now, with 3 templated textbox columns right next to each other, it seems impossible to multi-select the cells in those columns unless you extend the selection past the templated cols to include a "normal" col. In this example, for instance, unless you include the Order ID or Ship Country cols in the selection the templated cell remains in "edit mode" and no other cells get selected or added to the clipboard on CTRL-C.

This is a huge problem for me, because all my cells are templated, so there are no "normal" ones to select. Any suggestions?

Thanks again, Nick Muson



Window1_7d31cbbd.zip


RA Rajasekar Syncfusion Team July 21, 2011 12:53 PM UTC

Hi Nickolas,

Sorry for the inconvenience, you cannot draw highlight selection on the data template cells, because data tempalte cells will contains seprate controls or many controls. In this scenario, selection will be applied but due to datatemplated cells it is not visible. In this scenario, you perform multiple row selection by using row headers. please check the attached sample and video,

sample:

Selection1613598325.zip

Video:

selection-1954895202.zip

Please note, The datatemplated cell contains textbox means, the selection will be broken by that corresponding textbox text selection.So In this scenario, you cannot perform multiple cell selection.

Thanks,
Rajasekar



NM Nickolas Muson July 21, 2011 03:19 PM UTC

Thanks again Rajasekar

That is very disappointing news. Cell selection is pretty much a key part of any grid. It seems that the documentation should be more clear on this: you can have EITHER cell selection or cell templates, but not both. This is a pretty fatal flaw I think.

My main problem here is that I need to visually track "dirty" cells while the user is editing the grid, meaning an edited cell goes red until they commit all their changes (or manually un-do the cell edit), at which point it goes back to normal. There are some 60 columns per row that all need this functionality, and the Expression and Conditional Format columns don't cut it -- I need to be able to reference the Record.Data.IsDirty (or something like that) to set the bg color of the cell.

Can you think of another solution that will give me this functionality AND multi-cell selection? I could probably use QueryCellInfo to render changed cells differently, but that seems like a hack. One thing worth mentioning: I will be using a virtual GridControl to handle Excel-type formula support (but I haven't wired it up yet) so maybe that could be leveraged.

Also, another question: The GridDataControl columns support a CellItemTemplate and a CellEditItemTemplate, but all the samples and documentation mention is the CellItemTemplate. Could this somehow be leveraged to define a CellEditItemTemplate but not a CellItemTemplate, and control when the grid goes into "edit mode" more carefully? Either way, I am interested to see how the 2 different templates works -- is there any sample code available that uses CellEditItemTemplate?

I really have to come up with a solution for this problem with as little duct-tape as possible. The WPF functionality of the GridDataControl is kind of weak, but we're OK with that because we need the excel-type formula support, but if I have to hack cell selection then it might not be worth the large investment my company has to make to license the control.

I really appreciate all the support I've gotten from Syncfusion though, and that matters a lot too. Should I make this a DirectTrac case?

Nick Muson
Group One Trading




RA Rajasekar Syncfusion Team July 22, 2011 11:32 AM UTC

Hi Nick,

Thanks for your update.

We have prepared the sample based on your requirement, please find the sample in the below location,

Regarding CellEditItemTemplate and Color Change:

< http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=ColorChangeEditing1802164708.zip >

Regarding Formula Cell:

< http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=GC_FormulaCell-434236334.zip >

Regarding Multiple selection for DataTemplate Cells:

The corresponding multiple selection will done, but will be in background. Due to data templated cells, it is not invisible.

Please check the below video and sample,

Sample:

< http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=Selection-1961866291.zip >

Video:

< http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=MultipleSelection-786512819.zip >

Please let us know if you have any queries.

Thanks,
Rajasekar





NM Nickolas Muson July 22, 2011 03:58 PM UTC

Speedy delivery, as usual, thanks again. I am not feeling like we're any closer to a solution here though.

Sample 1:
The tracking of a "dirty" cell I already know how to do using a similar technique. This re-affirms that I cannot get multi-cell selection using this templated cells.

Sample 2:
I already have this one, and it's an excellent demonstration, but unfortunately it's not relevant to my current problem

Sample 3:
This one was the most disheartening, really, because it's seems to prove that what I need to do is not possible with the GridDataControl. I cannot present an app to our users that selects cells without any visual indication that the cells are selected -- if they are "invisibly" selected then from a user's pov they are really not selected at all.

I have to decide ASAP whether this is a showstopper or not. Copying and pasting multiple cells is an absolute key requirement of the app, there's no way around it.

Can we escalate this to find a solution?



RA Rajasekar Syncfusion Team July 25, 2011 03:34 PM UTC

Hi Nick,

Thanks for your update.

Regarding Multiple cell Selection:

Once the cell enters in to the edit mode of any data templated cell means, you cannot perform multiple selection by dragging. Because, here selection will be control by that corresponding data templated control and also grid cannot predicted which controls is inside the data templated cell. But, you can achieve this multiple selection behavior for data templated cells by using CellItemtemplate and CellEdItItemTemplate and by setting syncfusion:VisualContainer.WantsMouseInput property as False like shown be.

Code snippet[XAML]













Name="customersCombo" Background="White"
SelectedValue="{Binding Path=CellBoundValue,Mode=TwoWay}"
ItemsSource="{Binding Path=Style.ItemsSource}"
DisplayMemberPath="CustomerID"
SelectedValuePath="CustomerID"/>




For displaying the highlighted cell, you achieve by using the below code snippet,

Code Snippet[C#]

dataGrid.DrawSelectionOptions = GridDrawSelectionOptions.AlphaBlend;
dataGrid.HighlightSelectionAlphaBlend = Brushes.Red;

Regarding CopyPaste:

Once the data templated cell enters into edit mode, even though you select multiple cells in the grid , only the respective edit mode cell content will be copied to the clipboard. For instance, You can observe that behavior while debugging by using below code,

Clipboard.GetText();

And also please note, In GridDatacontrol copy paste will be applied based on the DataType of the Mapping Name of the GridDataControl.

For your reference, please find sample and video in the below location,

Sample:

< http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=CS-1798639161.zip >

Video:

< http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=DataTemplateMultiselect-1958411422.zip >

Similar query is posted in the incident #82877. For further calrification, please update your queries in the incident #82877 for better follow up.

Please let us know if you have any queries.

Thanks,
Rajasekar





FO Foram October 20, 2011 01:39 AM UTC

Hi,
I am using syncfusion. I have one problem with multi cell updation in data grid of wpf. I can select multi cell selection but I can not do multiple updation for those selected cells. say for example I have select R1 C2(Row 1 of cell 2), R1 Cell 10...so on my last cell selection which is R1C10 when I type text or number and hit enter that value goes to all selected cells(which are R1C2 and R1C10). can you please help with that or can you provide some sample code. Thanks.



JJ Jawahar Jeevanandan J Syncfusion Team November 28, 2011 11:27 AM UTC

Hi Foram,

Sorry for the inconvenience. We can update only single cell at a time, it is not possible to update multiple cells by selecting the range of cells.

Please let us know if you have any queries.

Thanks,
Jawahar.



Loader.
Live Chat Icon For mobile
Up arrow icon