datagridview使用总结
1.使用数据适配器sqldataAdapter填充datagridview
SqlConnection conn = new SqlConnection("server = ZHANGMING;user id = sa;pwd=!#%@$^;Database=Logic");
SqlDataAdapter dap = new SqlDataAdapter("SELECT M.[FID] AS 序号 ,M.[FName] AS 姓名,T1.FName AS 民族,T2.FName AS 性别 ,M.[FIDCard] AS 身份证,M.[FBirthday] AS 生日,T3.[FName] AS 学历 ,T4.[FName] AS 状态,M.[FEnrollDate] AS 登记日期 ,M.[FLeaveDate] AS 离职日期,T6.[FName] AS 职位,M.[FPhone] AS 手机,M.[FExtraPhone] AS 备用电话,M.[FAddress] AS 家庭住址 ,T5.[FName] AS 开户银行,M.[FBankID] AS 银行账号 ,M.[FDescription] AS 备注 FROM [Logic].[dbo].[Com_Employee] M LEFT JOIN Com_Submessage T1 ON M.FName = T1.FID LEFT JOIN Com_Submessage T2 ON M.FNation = T2.FID LEFT JOIN Com_Submessage T3 ON M.FEducation = T3.FID LEFT JOIN Com_Submessage T4 ON M.FStatus = T4.FID LEFT JOIN Com_Submessage T5 ON M.FBank = T5.FID LEFT JOIN Com_Submessage T6 ON M.FPosition = T6.FID", conn);
DataSet myDateSet = new DataSet();
dap.Fill(myDateSet);
dataGridView1.DataSource = myDateSet.Tables[0].DefaultView;
2.设置当前行为选中状态
datagridview1.currentrow.selected = true;
3.获取datagridview总的数值
for(int i = 0 ; i < datagridview1.rowcount; i++)
{
for(in j = 0 ; j < datagridview1.columncount; j++)
{
str = datagridview1.rows[i].cells[j].values.tostring();
}
}
4.在datagridview的最左方加上checkbox
DataGridViewCheckBoxColumn newColumn = new DataGridViewCheckBoxColumn();
newColumn.HeaderText = "";
newColumn.Width = 18;
dataGridView1.Columns.Insert(0, newColumn);
5.