每个按钮都添加到datagridview,具有不同的值 [英] Each buttons added to datagridview with different value

查看:72
本文介绍了每个按钮都添加到datagridview,具有不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的亲爱的。

我正常添加按钮到每个datagridview行并正确添加

所以我想做的是为每个按钮提供文本并且文本来了从数据,我可以这样做,但问题是它显示所有按钮中数据的最后一个值



  this  .tblaTableAdapter1.Fill( this  .dataSet11.tbla); 
dataGridViewX1.DataSource = dataSet11.tbla;
DataGridViewButtonColumn btnco = new DataGridViewButtonColumn();
dataGridViewX1.Columns.Add(btnco);
btnco.UseColumnTextForButtonValue = true ;
foreach (DataGridViewRow dr in this .dataGridViewX1.Rows)
{
btnco.Text = dr.Cells [ age ] Value.ToString();
}





我尝试过:



i tadd plus + to

btnco.Text + = dr.Cells [age]。Value.ToString();

它显示每个buttns中的所有行文本

解决方案

 DataGridViewButtonColumn btnco =  new  DataGridViewButtonColumn(); 
btnco.Name = MyButton;
dataGridViewX1.Columns.Add(btnco);
btnco.UseColumnTextForButtonValue = false ;
foreach (DataGridViewRow dr in this .dataGridViewX1.Rows)
{
DataGridViewCell button = dr.Cells [ MyButton ];
button.Value = dr.Cells [ age]。Value.ToString() ;
}


这样的事情可以帮助你入门:

 DataGridViewButtonCell b =  new  DataGridViewButtonCell(); 
int rowIndex = this .dataGridViewX1.Rows.Add(b);
this .dataGridViewX1.Rows [rowIndex] .Cells [ 0 ]。值= name;


hello dears .
im adding buttons to each datagridview row normally and it added correctly
so what i want to do is give text for each button and that text comes from data, i could do that but the problem is it shows the last value of data in all buttons

this.tblaTableAdapter1.Fill(this.dataSet11.tbla);
           dataGridViewX1.DataSource = dataSet11.tbla;
           DataGridViewButtonColumn btnco = new DataGridViewButtonColumn();
           dataGridViewX1.Columns.Add(btnco);
           btnco.UseColumnTextForButtonValue = true;
           foreach (DataGridViewRow dr in this.dataGridViewX1.Rows)
           {
               btnco.Text = dr.Cells["age"].Value.ToString();
           }



What I have tried:

i tadd plus + to
btnco.Text += dr.Cells["age"].Value.ToString();
it show all rows text in each buttns

解决方案

DataGridViewButtonColumn btnco = new DataGridViewButtonColumn();
btnco.Name = "MyButton";
dataGridViewX1.Columns.Add(btnco);
btnco.UseColumnTextForButtonValue = false;
foreach (DataGridViewRow dr in this.dataGridViewX1.Rows)
{
    DataGridViewCell button = dr.Cells["MyButton"];
    button.Value = dr.Cells["age"].Value.ToString();
}


Something like this should get you started:

DataGridViewButtonCell b = new DataGridViewButtonCell();
int rowIndex = this.dataGridViewX1.Rows.Add(b);
this.dataGridViewX1.Rows[rowIndex].Cells[0].Value = "name";


这篇关于每个按钮都添加到datagridview,具有不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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