saptechnique

Better late than never. - 郭富

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

view plaincopy to clipboardprint?
1、属性设置checkboxcolumn  
 
name:cb_check       
falsevalue:false      
truevalue:true 
datagridview中的readonly设置为false.  
 
2、  //单项选择设置  
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 flag = Convert.ToBoolean(checkCell.Value);  
                if (flag == true)     //查找被选择的数据行  
                {  
                    checkCell.Value = false;  
                }  
                    continue;  
             }  
        }  
 
   
 
3、获取选择的数据  
            int count = Convert.ToInt32(dgv_zy.Rows.Count.ToString());  
            for (int i = 0; i < count; i++)  
            {  
               //如果DataGridView是可编辑的,将数据提交,否则处于编辑状态的行无法取到  
                      dgv_zy.EndEdit();  
                DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)dgv_zy.Rows[i].Cells["cb_check"];  
                Boolean flag = Convert.ToBoolean(checkCell.Value);  
               if (flag == true)     //查找被选择的数据行  
                {  
                    //从 DATAGRIDVIEW 中获取数据项  
               string z_zcode = dgv_zy.Rows[i].Cells[0].Value.ToString().Trim();  
              //........................................                }  
         } 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/songkexin/archive/2009/12/03/4934143.aspx

posted on 2010-09-02 08:12  guofu  阅读(664)  评论(0编辑  收藏  举报