将文本框值加载到datagridview [英] loading textbox value to datagridview

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

问题描述

我写了一个代码来从文本框中为datagridview增加价值.............



I wrote a code to add value to datagridview from textbox.............

private void button1_Click(object sender, EventArgs e)
        {

            crsView.Rows.Add(txtName.Text, txtCredit.Text);
           

        }









但是当我运行代码时,以下消息显示:





无法以编程方式将行添加到DataGridView的行集合中控制是数据绑定。



请帮我提前。

提前谢谢





but when I run the code the following message shows:


"Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."

Please help me to ahead.
thanks in advance

推荐答案

试试这个: -

获取数据表并在其中添加行。然后将该表绑定为datasourse。

如果要追加到最后一行,则在数据表中添加先前的行,然后添加新行。

try this:-
Take data-table and add the row in it. Then bond that table as datasourse.
If you want to append to last row then add previous rows in data table then add new row.
private void button1_Click(object sender, EventArgs e)
        {
              DataTable table = new DataTable();
              table.Rows.Add(txtName.Text.trim(),txtCredit.Text.trim());
              crsView.datasource=table;
              crsView.DataBind();
        }


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

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