datagrid中double click事件里如何得到当前网格的横纵坐标?50分送!帮帮小弟吧。

huockham 2004-03-22 02:00:13
谢谢
...全文
59 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
seekg 2004-03-26
  • 打赏
  • 举报
回复
study.......
北京的雾霾天 2004-03-26
  • 打赏
  • 举报
回复
你是不是WEB的啊,WindowForm是有这个定义的
DataGrid.HitTest
如下:
.NET Framework 类库

DataGrid.HitTest 方法 (Point) [C#]请参见
DataGrid 类 | DataGrid 成员 | System.Windows.Forms 命名空间 | DataGrid.HitTest 重载列表 | MouseDown | DataGrid 成员(Visual J# 语法) | C++ 托管扩展编程
要求
平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列
语言
C#

C++

JScript

Visual Basic

全部显示
获取有关使用特定 Point 的网格的信息(如网格中被单击点的行号和列号)。

[Visual Basic]
Overloads Public Function HitTest( _
ByVal position As Point _
) As HitTestInfo

[C#]
public HitTestInfo HitTest(
Point position
);

[C++]
public: HitTestInfo* HitTest(
Point position
);

[JScript]
public function HitTest(
position : Point
) : HitTestInfo;

参数
position
一个 Point,它代表单个 x,y 坐标。
返回值
一个 DataGrid.HitTestInfo,它包含有关该网格的特定信息。

备注
DataGrid.HitTestInfo 与 System.Windows.Forms.DataGrid 控件的 HitTest 方法一起用来确定用户已单击 System.Windows.Forms.DataGrid 控件的哪一部分。DataGrid.HitTestInfo 包含单击的行、列和网格部分。另外,Type 属性返回一个 DataGrid.HitTestType 枚举。

HitTest 方法采用 x 和 y 参数,这些参数由 System.Windows.Forms.DataGrid 控件的以下事件提供:DragDrop、DragEnter、DragOver、MouseDown、MouseMove、MouseUp 和 MouseWheel。

示例
[Visual Basic] 下面的示例在用户单击网格时发生的事件中使用 HitTest 方法。

[Visual Basic]
Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim hti As DataGrid.HitTestInfo
hti = grid.HitTest(New Point(e.X, e.Y))
Select Case hti.Type
Case System.Windows.Forms.DataGrid.HitTestType.None
Console.WriteLine("You clicked the background.")
Case System.Windows.Forms.DataGrid.HitTestType.Cell
Console.WriteLine("You clicked cell at row " & hti.Row & ", col " & hti.Column)
Case System.Windows.Forms.DataGrid.HitTestType.ColumnHeader
Console.WriteLine("You clicked the column header for column " & hti.Column)
Case System.Windows.Forms.DataGrid.HitTestType.RowHeader
Console.WriteLine("You clicked the row header for row " & hti.Row)
Case System.Windows.Forms.DataGrid.HitTestType.ColumnResize
Console.WriteLine("You clicked the column resizer for column " & hti.Column)
Case System.Windows.Forms.DataGrid.HitTestType.RowResize
Console.WriteLine("You clicked the row resizer for row " & hti.Row)
Case System.Windows.Forms.DataGrid.HitTestType.Caption
Console.WriteLine("You clicked the caption")
Case System.Windows.Forms.DataGrid.HitTestType.ParentRows
Console.WriteLine("You clicked the parent row")
End Select
End Sub

[C#, C++, JScript] 没有可用于 C#、C++ 或 JScript 的示例。若要查看 Visual Basic 示例,请单击页左上角的“语言筛选器”按钮 。

要求
平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列

请参见
DataGrid 类 | DataGrid 成员 | System.Windows.Forms 命名空间 | DataGrid.HitTest 重载列表 | MouseDown | DataGrid 成员(Visual J# 语法) | C++ 托管扩展编程

huockham 2004-03-22
  • 打赏
  • 举报
回复
当然也可以用DataGrid.CurrentRowIndex和DataGridCrrentColumnIndex

这个办法不行。早试过了。
huockham 2004-03-22
  • 打赏
  • 举报
回复
不行啊。不包含对HitTest的定义啊
北京的雾霾天 2004-03-22
  • 打赏
  • 举报
回复
当然也可以用DataGrid.CurrentRowIndex和DataGridCrrentColumnIndex
北京的雾霾天 2004-03-22
  • 打赏
  • 举报
回复
private Point m_CurPoint;

private void ListDataGrid_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
m_CurPoint=new Point(e.X,e.Y);
}

private void ListDataGrid_DoubleClick(object sender, System.EventArgs e)
{
if (this.HitTest(m_CurPoint.X,m_CurPoint.Y).Row<0)
{
return;
}
if (this.HitTest(m_CurPoint.X,m_CurPoint.Y).Column<0)
{
return;
}
if (OnDoubleClickRow!=null)
{
OnDoubleClickRow(this,this.CurrentRowIndex);
}
}

可以参考一下这个用法
jQuery EasyUI是一组基于jQuery的UI插件集合,而jQuery EasyUI的目标就是帮助web开发者更轻松的打造出功能丰富并且美观的UI界面。开发者不需要编写复杂的javascript,也不需要对css样式有深入的了解,开发者需要了解的只有一些简单的html标签 1.3.6更新 Bug treegrid: getChecked方法不能返回正确的行. fixed. tree: 异步树,在onlyLeafCheck:true时复选框不显示正确. fixed. Improvement treegrid:继承datagrid组件所有的selecting和checking方法。 linkbutton:图标对齐方式,支持值:'top','bottom','left','right'。 linkbutton:添加"size"属性,支持值:'small','large'。 linkbutton:添加的onClick事件。 menubutton:添加"menuAlign"属性,允许用户设置顶级菜单对齐。 combo:添加"panelAlign"属性,支持值:'left','right'。 calendar:"formatter"、"styler"和"validator"选项可用于自定义日历日期。 calendar:添加的onChange事件。 panel:添加"method","queryParams"和"loader"属性。 panel:添加"onLoadError"事件datagrid:添加"onBeginEdit"事件datagrid:添加"onEndEdit"事件datagrid:添加"sort"方法和"onBeforeSortColumn"事件datagrid:"combogrid"编辑器集成到datagriddatagrid:添加"ctrlSelect"属性,允许使用ctrl+click 多选 slider:添加"converter"选项,允许用户决定如何将一个值转换为滑块的位置或滑块位置值。 searchbox:添加"disabled"属性。 searchbox:添加"disabled","enable","clear","reset"方法。 spinner:添加"readonly"属性、"readonly"方法和"onChange事件

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧