博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2011年4月6日

摘要: dgv1.DataSource=null是因为你并没有给DataSource赋值啊。通常的做法是: 1.先得到你从数据库里提取数据的数据集ds 2.然后给dataGridView的DataSource赋值。dgv1.DataSource=ds.Tables[0]; 3.绑定dataGridView.DataBind(); 因为你没有进行第二部,所以你反向取值是得不到DataSet的。 不晓得你为什么要把数据直接循环加到dataGridView里。建议可以用循环先建立一个DataTable,然后绑定到dataGridView上。 这样在以后想获得DataSource的数据源就可以直接获得了。 - 阅读全文

posted @ 2011-04-06 23:41 moss_tan_jun 阅读(685) 评论(0) 推荐(0) 编辑

摘要: 一个DataGridView简单应用示例,只是简单的实现了DataGridView的数据绑定、添加、修改和删除的操作,先看代码: view plaincopy to clipboardprint? using System; using System.Data; using System.Windows.Forms; namespace DataGridView { public partial class frmMain : Form { public frmMain() { InitializeComponent(); } private DataSet addressList; priv 阅读全文

posted @ 2011-04-06 23:36 moss_tan_jun 阅读(2606) 评论(0) 推荐(0) 编辑

摘要: 我们在使用DatagridView的列样式的时候很方便,可以设置成comboboxcolumn,textboxcolumn等等样式,使用起来非常方便,但是,这样设置的列都采用同一种样式.对同一列采用多种样式的,就需要单独对单元格进行操作了.具体方法如下:1.实例化一个定义好的控件:如combobox2.初始化combobox控件3.获取 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.CurrentCell.ReadOnly == false 阅读全文

posted @ 2011-04-06 23:32 moss_tan_jun 阅读(2741) 评论(0) 推荐(0) 编辑

摘要: DataGridViewCheckBoxColumn newColumn = new DataGridViewCheckBoxColumn();newColumn.HeaderText = "选择";dataGridView1.Columns.Add(newColumn);这样添加的列是放在最后一列,也许你希望它在其它列,例如第二列,那么可以:dataGridView1.Columns.Insert(1, newColumn);DataGridView中的DataGridViewCheckBoxColumn是很难控制的,当 DataGridView 未绑定到数据时,对单元格 阅读全文

posted @ 2011-04-06 23:18 moss_tan_jun 阅读(34985) 评论(1) 推荐(1) 编辑

摘要: 方法一:private void dgv_zy_CellContentClick(object sender, DataGridViewCellEventArgs e){ int count = Convert.ToInt16(dgv_zy.Rows.Count.ToString()); for (int i = 0; i < count; i++) { DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)dgv_zy.Rows[i].Cells["cb_check"]; Boolean fla 阅读全文

posted @ 2011-04-06 23:13 moss_tan_jun 阅读(2030) 评论(0) 推荐(0) 编辑

摘要: this.dataGridView1.Columns["UnitPrice"].DefaultCellStyle.Format="c";this.dataGridView1.Columns["ShipDate"].DefaultCellStyle.Format="d"; 阅读全文

posted @ 2011-04-06 22:41 moss_tan_jun 阅读(256) 评论(1) 推荐(0) 编辑