将数据绑定到Datagridview后如何显示值? [英] How to show values after binding data to Datagridview?

查看:61
本文介绍了将数据绑定到Datagridview后如何显示值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

将数据绑定到DataGridView之后,我想在datagridviewtextboxcolumn中显示一些值.

这是我的代码:

Hi all

i want to show some values in datagridviewtextboxcolumn after binding data to DataGridView.

Here is my code:

DataGridViewTextBoxColumn TxtCol = new DataGridViewTextBoxColumn();
DataTable dtGridEdit = new DataTable();
 for (int i = 0; i < 4; i++)
                    {
                        dr = dtGridEdit.NewRow();
  dtGridEdit.Rows.Add(dr);
                    }
                    dgridEdit.DataSource = dtGridEdit;
                    dgridEdit.Columns.Add(TxtCol);
                    if (dtGridEdit.Rows.Count > 0)
                    {
                        dgridEdit.Rows[1].Cells[0].Value = "1";
                        dgridEdit.Rows[1].Cells[0].Value = "9";
                        dgridEdit.Rows[2].Cells[0].Value = "10";
                        dgridEdit.Rows[3].Cells[0].Value = "11";
                    }


在运行时,值将显示在dgridEdit中.
如果您知道,请告诉我.

问候,
Pawan.


at runtime, values are displayed in the dgridEdit.
if u know, do let me know.

Regards,
Pawan.

推荐答案

pls在您的代码中进行更改

dgridEdit.Rows [1] .Cells [coloum name] .Value ="1";


还覆盖了数据

dgridEdit.Rows [1] .Cells [0] .Value ="1";
dgridEdit.Rows [1] .Cells [0] .Value ="9";
pls make the changes in your code

dgridEdit.Rows[1].Cells[coloum name].Value = "1";


also you are overwritting the data

dgridEdit.Rows[1].Cells[0].Value = "1";
dgridEdit.Rows[1].Cells[0].Value = "9";


在这里看不到问题或不理解问题.以相同的方式,您可以在第一次绑定后绑定textboxcolumn值:

dgridEdit.Rows [someRowIndex] .Cells [yourTextBoxColumnIndex] .Value ="some Text";
Can''t see the problem here or didn''t understand the issue. In the same manner you can bind textboxcolumn values after the first binding:

dgridEdit.Rows[someRowIndex].Cells[yourTextBoxColumnIndex].Value = "some Text";


这篇关于将数据绑定到Datagridview后如何显示值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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