datagrid行操作

//获取第一个被选中的行

var row=$('#dg').datagrid('getSelected');

//获取行对应的索引值

var index=$('#dg').datagrid('getRowIndex',row);

//对该索引值对应的行进行选中操作

$('#dg').datagrid('selectRow',index);

转载于:https://www.cnblogs.com/s-d-g/p/8359151.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WPF DataGrid 支持拖拽的实现方式如下: 1. 首先,需要在 DataGrid 控件上启用拖拽功能,可以通过设置 CanUserSortColumns 和 CanUserReorderColumns 属性为 true 来实现。 2. 然后,需要为 DataGrid 控件的设置拖拽事件,可以使用 PreviewMouseMove 和 PreviewMouseLeftButtonDown 事件来实现。 3. 在 PreviewMouseLeftButtonDown 事件中,需要使用 VisualTreeHelper.GetParent 方法来获取所选DataGridRow 控件。 4. 在 PreviewMouseMove 事件中,需要使用 DragDrop.DoDragDrop 方法来开始拖拽操作,并设置拖拽数据的格式和数据对象。 5. 最后,在 DataGrid 控件上订阅 Drop 事件,实现的拖拽功能。 示例代码如下: ```xml <DataGrid CanUserSortColumns="True" CanUserReorderColumns="True" PreviewMouseMove="DataGrid_PreviewMouseMove" PreviewMouseLeftButtonDown="DataGrid_PreviewMouseLeftButtonDown" Drop="DataGrid_Drop"> </DataGrid> ``` ```c# private void DataGrid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { DataGridRow row = FindAncestor<DataGridRow>((DependencyObject)e.OriginalSource); if (row != null) { // 设置拖拽数据的格式和数据对象 DataObject dragData = new DataObject(DataFormats.Serializable, row.DataContext); DragDrop.DoDragDrop(row, dragData, DragDropEffects.Move); } } private void DataGrid_PreviewMouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { DataGridRow row = FindAncestor<DataGridRow>((DependencyObject)e.OriginalSource); if (row != null) { // 开始拖拽操作 DragDrop.DoDragDrop(row, row.DataContext, DragDropEffects.Move); e.Handled = true; } } } private void DataGrid_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.Serializable)) { // 获取拖拽数据的数据对象 var data = e.Data.GetData(DataFormats.Serializable) as YourDataObject; if (data != null) { // 处理拖拽逻辑 // ... } } } private static T FindAncestor<T>(DependencyObject current) where T : DependencyObject { do { if (current is T ancestor) { return ancestor; } current = VisualTreeHelper.GetParent(current); } while (current != null); return null; } ``` 注意,在上面的示例代码中,要根据实际情况修改拖拽操作中的数据格式和数据对象。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值