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

查看:37
本文介绍了将 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..

控件有很多事件;一个是默认事件,这可以通过双击设计器中的控件本身来生成.但最终您将需要所有 3 种方法来生成连接事件,(有时还需要删除它们.)

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天全站免登陆