c# - 如何获取 DataGridView 中的当前单元格位置 x 和 y?

标签 c# .net datagridview

我有一个带有隐藏日历的 Windows 窗体。我想在 DataGridView 的当前单元格正下方显示表单。位置根据当前单元格的位置而变化。

我不想要当前单元格或当前列,我想要位置以便我可以设置我的日期表单的位置。

这是我正在使用的但它不起作用:

int po_X = paygrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Left+paygrid.Left;
int po_Y = paygrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Bottom+paygrid.Top;
form_date.Location = new System.Drawing.Point(po_X, po_Y);

最佳答案

您可以使用 paygrid.PointToScreen() 方法。

form_date.Location = paygrid.PointToScreen(
   paygrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location);

关于c# - 如何获取 DataGridView 中的当前单元格位置 x 和 y?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9619746/

相关文章:

c# - 对多个任务使用 async/await

c# - 防止数据绑定(bind) DataGridView 在编辑时进行排序

c# - 使用 dateTimePicker 在 DataGridView 中编辑日期

c# - 如果第一次没有找到任何内容,如何正确地多次查询数据库以获取某个值 C#

c# - Linq Boolean 返回异常 DROPDOWNLIST 有一个无效的 SelectedValue,因为它不存在于项目列表中

c# - 如何从 web.config 中读取 system.web 部分

mysql - 在 VB.NET 中更新 DGV 中的多个选定行

c# - 登录 session 并希望在 Asp.Net C SHArp 中以用户名作为主键创建新表详细信息

c# - 错误 : A project with an out put type of class library

.net - 有人有一个例子说明为什么我要自行托管 WCF 服务吗