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

huockham 2004-03-22 02:00:13
谢谢
...全文
64 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用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);
}
}

可以参考一下这个用法

111,098

社区成员

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

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

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