如何将文本框与datagridview绑定 [英] how to bind textbox with datagridview

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

问题描述

嗨亲爱的

我有一个由数据库填充的datagridview
我想将textBox与用户单击并每次
的gridView中的单元格绑定 用户单击其他单元格上的textBox.text change

hi dear

I have a datagridview that fill by database
I want bind textBox with cell in gridView that User click and each time
user click on other cells textBox.text change

推荐答案

尝试
private void dgvTst_CellClick(object sender, DataGridViewCellEventArgs e)
{
    if (txtTst.DataBindings.Count > 0)
        txtTst.DataBindings.RemoveAt(0);

    // The code binds column index 2 to the TextBox control
    txtTst.DataBindings.Add(
        new Binding("Text", dgvTst[2, e.RowIndex], "Value", false) );
}



参考链接:-如何将文本框绑定到DataGridView列 [ ^ ]



Reference Link :- How to bind a TextBox to a DataGridView column[^]


这是最简单的方法:

This is the easiest way:

txtResult.Text = dgvItems.SelectedRow.Cells[0].Value;



其中0是单元格的索引.

如果这解决了您的问题,请将其标记为答案.

最好的问候,
爱德华



wherein 0 is the index of the cell.

Mark this as answer if this solved your problem.

Best regards,
Eduard


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

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