Select rows by RowHeader

Mar 19, 2009 at 3:13 AM
Edited Mar 19, 2009 at 3:13 AM
I want to user selected one row or multi-rows only when user click the RowHeader or multi-RowHeader of the rows.
And it means user can't select the full rows in a DataGrid directly following default way.

Does anyone know how to do it, thanks?
Mar 24, 2009 at 3:18 AM

I found it, it's so simple by setting SelectionUnit="CellOrRowHeader"

 

 

Mar 24, 2009 at 3:57 PM

But it lose the ability MultiSelect by Ctrl/Shift Key when I select rows by RowHeader?

How can solve it? Thanks.

Coordinator
Mar 24, 2009 at 9:05 PM
When SelectionUnit is FullRow or CellOrRowHeader, you should be able to select rows when clicking on the headers. Perhaps I don't understand exactly what you're trying to achieve.

Ben
Mar 25, 2009 at 4:36 AM

Thank your reply!
I found it caused by my code. Because I want to do multi-row drag, so before I use selectedItem to get row. And later maybe I'll use selectedItems

DataItemType selectedItem = dgPointCloud.SelectedItem as DataItemType;
if (selectedItem != null)
{
DataGridRow row = (DataGridRow)dgPointCloud.ItemContainerGenerator.ContainerFromItem(selectedItem);
if (null != row && !row.IsEditing)
...


So if select one row, then select another row just by click row header, both the two rows will be selected, even more, they'll do drag and drop immediately. After I read other sample code and use the following replace, it's no problem.

DataGridRow row = FindVisualParent<DataGridRow>(e.OriginalSource as FrameworkElement);
if ((row != null) && !row.IsEditing && row.IsSelected)
...

But I'm still not clear how to do Multi-Row Drag&Drop now.

Thanks
Dan


From: [email removed]
To: [email removed]
Date: Tue, 24 Mar 2009 13:05:16 -0700
Subject: Re: Select rows by RowHeader [wpf:50598]

From: BenCarter
When SelectionUnit is FullRow or CellOrRowHeader, you should be able to select rows when clicking on the headers. Perhaps I don't understand exactly what you're trying to achieve.

Ben


�������� MSN �����ܣ����� MSN ��ȫ�ȶ��� ���ھ����أ�
Coordinator
Mar 25, 2009 at 7:20 PM
When you say multi-row drag or multi-row drag and drop, are you referring to being able to select multiple rows by pressing down on a header and dragging the mouse, or are you referring to re-ordering the items by selecting one or more rows and then dragging them to a new location?

If the former, then you should not need to implement anything, since the header behavior should already be that way.

If the later, then you will need to essentially override the existing mouse behavior when clicking on a row that is already selected.

Ben
Mar 26, 2009 at 3:03 AM
Edited Mar 26, 2009 at 7:10 AM
Unfortunately, my intent is the later option. Not only re-order, I have to drag mulit-rows and drop into another row as child nodes so it looks like a tree in datagrid:-)

Thanks Dan