private void dgvUserInfo_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if(e.Value is bool)
{
if ((bool)e.Value)
{
e.Value = "男";
}
else
{
e.Value = "女";
}
}
}
C# Windows DataGridView 判斷 CheckBox 選取的方法
不熟的東東只能靠Debug去了解了呵呵,記下來,以後或許有機會用到^_^
1 foreach (DataGridViewRow dgR in this.dataGridView1.Rows)
2 {
3 try
4 {
5 DataGridViewCheckBoxCell cbx = (DataGridViewCheckBoxCell)dgR.Cells[0];
6 if ((bool)cbx.FormattedValue)
7 {
8 //TODO:
9 }
10
11 }
12 catch (Exception ex)
13 {
14 MessageBox.Show(ex.Message);
15 }
16
17 }
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue==true)
{
//TODO
}
}
DataGridView的常用用法 //读取表Supplier并绑定到GridView中
private void BindGvSupplier()
...{
OracleConnection conn = this.Conn();
OracleCommand cmd = new OracleCommand( "select * from Supplier ", conn);
OracleDataAdapter sda = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds, "Supplier "); 网管有家www.bitscn.net
string[] SuppId = new string[ds.Tables[ "Supplier "].Rows.Count];
for (int i = 0; i < ds.Tables[ "Supplier "].Rows.Count; i++)
...{
SuppId[i] = ds.Tables[ "Supplier "].Rows[i][0].ToString();
}
this.gvSupplier.DataSource = ds.Tables[ "Supplier "];
this.gvSupplier.DataKeyNames[0] = "SuppId ";
this.gvSupplier.DataBind();
this.lblPageIndex.Text = Convert.ToString(int.Parse(this.gvSupplier.PageIndex.ToString()) + 1);
this.lblTotalPage.Text = this.gvSupplier.PageCount.ToString();
this.lblCount.Text = this.GetTotalCount().ToString();
}
中国网管论坛bbs.bitsCN.com
//分页触发的事件
protected void gvSupplier_PageIndexChanging(object sender, GridViewPageEventArgs e)
...{
this.gvSupplier.PageIndex = e.NewPageIndex;
this.BindGvSupplier();
this.lblPageIndex.Text = Convert.ToString(int.Parse(this.gvSupplier.PageIndex.ToString()) + 1);
this.cbAllSelect_CheckedChanged(this.cbAllSelect, e);
}
网管u家u.bitsCN.com
//删除按钮触发的事件
protected void gvSupplier_RowDeleting(object sender, GridViewDeleteEventArgs e)
...{
int id = e.RowIndex; 网管u家www.bitscn.net
GridViewRow gvr = this.gvSupplier.Rows[id];
int SuppId=int.Parse(((HyperLink)(gvr.Cells[7].Controls[0])).Text.ToString());
string sqlString = "delete from Supplier where SuppId= " + SuppId;
//如果本页只有一条数据,删除后要向前翻一页
if (this.gvSupplier.Rows.Count == 1)
...{
if (this.gvSupplier.PageIndex > 1)
...{
this.gvSupplier.PageIndex--;
}
}
int result = ExecuteSql(sqlString);
if (result == 1)
...{
this.Alert( "你成功删除一条数据 ", this.Page);
}
this.BindGvSupplier();
this.BindGvSupplier();
网管网www_bitscn_com
} 网管bitscn_com
//绑定删除按钮的确认提示
protected void gvSupplier_RowDataBound(object sender, GridViewRowEventArgs e)
...{
if (e.Row.RowType == DataControlRowType.DataRow)
...{
LinkButton myLb = (LinkButton)(e.Row.Cells[8].Controls[1]);
myLb.Attributes.Add( "onclick ", "javascript:return confirm( '你确认删除 "+e.Row.Cells[0].Text+ "吗? ') ");
//鼠标经过时改变行的颜色
e.Row.Attributes.Add( "onmouseover ", "this.style.backgroundColor= '#ffffe7 ' ");
e.Row.Attributes.Add( "onmouseout ", "this.style.backgroundColor= 'transparent ' ");
}
} 网管联盟bitsCN@com
//执行一条Oracle语句
private int ExecuteSql(String sqlString)
...{
//try
//{
OracleConnection conn = this.Conn();
conn.Open();
OracleCommand cmd = new OracleCommand(sqlString, conn);
int effectedLine = cmd.ExecuteNonQuery();
conn.Close();
return effectedLine;
/
【转自www.bitsCN.com】
for (int i=0;i < dataGridView1.count-1;i++)
{
dataGridView1.Rows[i].Cells[学号是第几列].Value=0;
}
用dataGridView1[列][行].value=0 直接赋也可以
最常见的数据绑定:
string sqlStr=数据库查询语句;
DataManager db = new DataManager();
DataSet ds = db.ExcuteSelectCmd(sqlStr);
DataGridView.DataSource = ds.Tables[0];
对DataGridViewCheckBoxColumn列进行动态添加,赋值,判定选中
添加:
DataGridViewCheckBoxColumn select = new DataGridViewCheckBoxColumn();
select.HeaderText = " 选择";
select.Width = 100;
dataGridView1.Columns.Insert(0, select);//添加到dataGridView
赋值:
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[0];
chk.Value=true;
}
控制其显示状况即当.Value = false时显示为未选中,为ture是显示为选中,此时需要设置其readonly属性为ture,否则只有当选中其他时才会有反应!
(这个是我后来加的,查了好长时间,如果对你有用,支持一下!)
判定选中:
for (int i = 0; i < dataGridView1.Rows.Count ; i++)
{
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[0];
if (chk != null && (bool)chk.FormattedValue)
{
}
}
对单元格的点击事件响应:(对其他,如按钮等的响应也可以一样的处理)
private void CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 需要的列的号)
{
string str = DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString().Trim();
txt_areaAmend.Text = str;
pne_areaAmend.Visible = false;
}
}
设置其选择的模式: 在其属性中设置SelectionMode,可以让其选择是整行还是整列,然后通过 groundID = dataGridView1.SelectedRows[0].Cells ["宗地编号"].Value.ToString().Trim();//获得所选记录的宗地编码
对其进行删除操作 dt.Rows[i].Delete();(事实上这个完全可以在使用的时候自己想到是这样的,不过为了省事,防止忘记,我还是把他写在这了!)
没有合适的资源?快使用搜索试试~ 我知道了~
True和False.rar
共1个文件
txt:1个
需积分: 9 2 下载量 69 浏览量
2008-11-07
20:20:44
上传
评论
收藏 3KB RAR 举报
温馨提示
True和False.rarTrue和False.rarTrue和False.rarTrue和False.rarTrue和False.rarTrue和False.rarTrue和False.rar
资源推荐
资源详情
资源评论
收起资源包目录
True和False.rar (1个子文件)
True和False.txt 7KB
共 1 条
- 1
资源评论
a415529307
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功