在DataGridView中确定单元格位置

给定特定的行号和列索引,如何计算DataGridView中的单元格位置(IE:Location.Point)?

我需要单元格位置的原因是我可以在单元格内放置一个按钮以允许文件夹浏览(datagridview显示文件夹路径)。

关于如何实现这种欢迎的替代建议。

你无法真正找到DGV单元的一个点,因为单元占据了DGV中的矩形区域。 但是,您可以使用DataGridView.GetCellDisplayRectangle()方法找到此区域。 它返回一个Rectangle用于由Cell的列和行索引给出的DGV Cell的显示区域。 如果你真的想要一个点,你可以很容易地使用Rectangle为任何一个Rectangle的四个角构造点。

 // Get Rectangle for second column in second row. var cellRectangle = dataGridView1.GetCellDisplayRectangle(1, 1, true); // Can create Points using the Rectangle if you want. Console.WriteLine("Top Left x:{0}\ty:{1}", cellRectangle.Left, cellRectangle.Top); Console.WriteLine("Bottom Right x:{0}\ty:{1}", cellRectangle.Right, cellRectangle.Bottom); 

但我同意你的问题的评论者; 最好创建一个自定义DataGridViewColumn并在那里托管TextBox和Button。 这是为DateTimePicker控件执行此操作的示例 :