如何在datagridview中显示文本框中的选择行 [英] how to display select row in textbox from datagridview

查看:255
本文介绍了如何在datagridview中显示文本框中的选择行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从下面的代码中我可以显示从datagridview到文本框的所选数据,但只有当我点击内容但是当我点击内容不在的单元格时它才会显示文本字段中的数据。



From the below code am able to show the selected data from datagridview to textbox but it happens only when i click on the content but when i click on the cell where the content is not there its not displaying the data in the text fields.

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
       {
           if (e.RowIndex >= 0)
           {
               DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];

               TxtName.Text = row.Cells["Name"].Value.ToString();
               TxtPath.Text = row.Cells["Path"].Value.ToString();


           }
       }

推荐答案

这是您使用的预期行为 CellContentClick 方法。它只在你点击实际内容而不是它之后的空白区域时触发。



如果你希望在你点击的任何地方发生这种情况然后,单元格使用 CellClick 事件。
This is expected behaviour as you have used the CellContentClick method. It only fires when you click the actual content and not the white space after it.

If you want this to happen wherever you click in the cell then use the CellClick event instead.


这篇关于如何在datagridview中显示文本框中的选择行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆