如何插入值到DataGridView的单元格? [英] how to insert value into DataGridView Cell?

查看:180
本文介绍了如何插入值到DataGridView的单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的DataGridView(即持有任何数据库)

i have DataGridView (that hold any DataBase)

我要插入任意值到任何单元格(而这个值将保存在数据库)

i want to insert any value into any Cell (and that this value will save on DataBase)

如何做到这一点(在C#)

how to do it (in C#)

感谢的提前

推荐答案

您可以通过以下方式访问任何DGV细胞:

You can access any DGV cell as follows :

dataGridView1.Rows[rowIndex].Cells[columnIndex].Value = value;



但通常最好使用数据绑定:你绑定DGV到数据源(数据表,集...)通过数据源属性,唯一的工作数据源本身。在 DataGridView的将自动反映在 DataGridView中所做的更改和变更将在数据源上反映出来。

But usually it's better to use databinding : you bind the DGV to a data source (DataTable, collection...) through the DataSource property, and only work on the data source itself. The DataGridView will automatically reflect the changes, and changes made on the DataGridView will be reflected on the data source

这篇关于如何插入值到DataGridView的单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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