1、
DataSet ds = new DataSet();
ds = module.GetInStockInfo(); //获取ds数据源的方法
this.DataGridView.DataSource = ds.Tables[0];
2、两个DateTimePicker控件值得比较
DateTime.Compare(this.dtpstartData.Value, this.dtpEndData.Value) > 0; //dtpstartData<dtpEndData
string startdate = this.dtpstartData.Value.ToString("yyyy-MM-dd"); this.dtpstartData.ToString() == this.dtpEndData.ToString()
3、查询到的DataTable中“cell”列的值
dt.Rows[0]["cell"].ToString();
4、将点击到的值复制到文本框中
int index = e.RowIndex;
this.txtInvBatchCode.Text = DataGridView.Rows[index].Cells["Batch"].Value.ToString();
this.dtpProductDate.Text = DataGridView.Rows[index].Cells["ProductDate"].Value.ToString() //赋值DateTimePicker的值
5、添加DataGridView的行
int index = this.DataGridView.Rows.Add();
this.DataGridView.Rows[index].Cells["Batch"].Value = this.txtInvBatchCode.Text;
this.DataGridView.Rows[index].Cells["ProductDate"].Value = this.dtpProductDate.Value;
6、普通事件中获取选择到的某列的值
this.DataGridView.SelectedRows[n].Cells["Batch"].EditedFormattedValue.ToString()
7、删除选中行
this.DataGridView.Rows.Remove(this.DataGridView.Rows[DataGridView.CurrentRow.Index]);