开发者

Drag & drop list view item on a Datagrid header in WPF

开发者 https://www.devze.com 2023-03-25 12:38 出处:网络
Trivial, but I got really stuck on it... How on Earth can I find out wh开发者_JAVA技巧ich DataGrid column (or header) the item was dropped on?? I can see no retrievable info on that within the DataGri

Trivial, but I got really stuck on it... How on Earth can I find out wh开发者_JAVA技巧ich DataGrid column (or header) the item was dropped on?? I can see no retrievable info on that within the DataGrid.Drop event.


I'm just programming some dataGrid D&D at the moment, and the only way I've found to do what you ask is to put the Drop listener on each dataGridColumnHeader and on each DataGridCell.

as I write, I've got Drop listeners on my cells, dataGridColumnHeaders and datagrids (for the drop in the background of the datagrid, in case you haven't got enough rows/columns to fill the DG).

those listeners get the cell's Row/col index where it applies using something like myDataGrid.Columns.IndexOf(((DataGridCell)sender).Column) in the cell's drop listener and then call a common method in my DG's class.

it's actually not as messy as you'd think.

edit: regarding your comment: "But how do you attach an event handler to DataGrid header?"

in your MyDataGrid.xaml for instance:

<DataGrid.ColumnHeaderStyle>
    <Style TargetType="{x:Type DataGridColumnHeader}">
        <EventSetter Event="DropEvent" Handler="ColumnHeaderDropHandler" />
    </Style>
</DataGrid.ColumnHeaderStyle>

and of course, you need to implement ColumnHeaderDropHandler in your code behind.

0

精彩评论

暂无评论...
验证码 换一张
取 消