将DataGridView值复制到TextBox [英] Copy DataGridView values to TextBox

查看:134
本文介绍了将DataGridView值复制到TextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试得到一个答案,但到目前为止,没有帮助可以做我想要的。

I have tried to get an answer to this but so far no help has been able to do what I want it to.

我有这段代码,这意味着查看所选行并将其输出到相应的文本框中。

I have this piece of code, which is meant to look at the selected row and output it's columns into the corresponding text boxes.

 private void DataGridView01_SelectionChanged(object sender, EventArgs e)
 {
    if (DataGridView01.SelectedRows.Count > 0)
    {
       personIDTextBox.Text = DataGridView01.SelectedRows[0].Cells[0].Value.ToString();
       comboBox1.Text = DataGridView01.SelectedRows[0].Cells[1].Value.ToString();
       Txt_FirstName.Text = DataGridView01.SelectedRows[0].Cells[2].Value.ToString();
       mIDDLENAMETextBox.Text = DataGridView01.SelectedRows[0].Cells[3].Value.ToString();
       sURNAMETextBox.Text = DataGridView01.SelectedRows[0].Cells[4].Value.ToString();
       cITYTextBox.Text = DataGridView01.SelectedRows[0].Cells[5].Value.ToString();
       eMAILTextBox.Text = DataGridView01.SelectedRows[0].Cells[6].Value.ToString();
     }
  }

当我启动程序时,我没有错误,它不会将数据输出到文本框中。任何人都知道我做错了什么?

When I launch the program, I get no errors but it doesn't output the data into the textbox. Anyone know what I am doing wrong?

推荐答案

HOOKING UP EVENTS:

HOOKING UP EVENTS:

这是您需要学习在VS中编写代码的最基本的事情。简而言之,这意味着事件名称,这里 DataGridView01_SelectionChanged 连接到事件。为此,可以使用代码或将其插入到属性选项卡的事件窗格的正确插槽中。选择 DataGridView ,打开事件窗格(带闪存的窗格),并找到SelectionChanged事件!这里插入事件的名称,你完成了。

It is the most basic thing you need to learn to code in VS. In short it means that the event name, here DataGridView01_SelectionChanged is connected to the event. To do so one can either use code or one inserts it into the correct slot of the events pane of the property tab. Select the DataGridView, open the events pane (the one with the flash) and locate the SelectionChanged event! Here insert the name of the event and you are done.

(我只安装了VS的德文版本..)

(I only have the German versions of VS installed..)

结果反映在form_designer.cs文件中,它是一样的(在反向)作为双击该位置,然后填写生成的代码存根。

The result is reflected in the form_designer.cs file and it is the same thing (in reverse) as double clicking that spot and then filling in the generated code stub..

控件有许多事件;一个是默认事件,这可以通过设计器中的双击控件本身来生成。但是最终,您将需要通过生成连接三种方式来实现事件(以及有时删除它们)。

Controls have many events; one is the default event and this can be generated by double clicking the control itself in the designer. But eventually you will need all 3 ways to generate and hook up the events, (as well as sometimes removing them.)

这篇关于将DataGridView值复制到TextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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