关于XtraGrid的使用(GridControl小结)

定义焦点行的方法: gridView_bcode.FocusedRowHandle = focuseRowInt; //通过设置GridView 的FocusedRowHandle属性
 
view plaincopy to clipboardprint?
//获取焦点行任意单元格的数据    
ColumnView cv = (ColumnView)gridControl_Gongzi.FocusedView;//重新获取此ID 否则无法从表头连删获取不到id   
                        int focusedhandle = cv.FocusedRowHandle;   
                        object rowIdObj = gridView1.GetRowCellValue(focusedhandle, "id");   
                        if (DBNull.Value != rowIdObj)   
                        {   
                            FocusedRow_id = Convert.ToInt32(rowIdObj);   
                        }  
//获取焦点行任意单元格的数据 
ColumnView cv = (ColumnView)gridControl_Gongzi.FocusedView;//重新获取此ID 否则无法从表头连删获取不到id
                        int focusedhandle = cv.FocusedRowHandle;
                        object rowIdObj = gridView1.GetRowCellValue(focusedhandle, "id");
                        if (DBNull.Value != rowIdObj)
                        {
                            FocusedRow_id = Convert.ToInt32(rowIdObj);
                        }
 view plaincopy to clipboardprint?
//当数据发生变化时执行    
     private void gridView1_CellValueChanged(object sender, CellValueChangedEventArgs e)   
     {   
         int intRowHandle = e.RowHandle;   
         FocusedRow_bumen = Convert.ToString(gridView1.GetRowCellValue(intRowHandle, "bumen"));   
         FocusedRow_xingming = Convert.ToString(gridView1.GetRowCellValue(intRowHandle, "xingming"));   
         //FocusedRow_jibengongzi = Convert.ToDecimal(gridView1.GetRowCellValue(intRowHandle, "jibengongzi"));   
         object rowJibengongziObj = gridView1.GetRowCellValue(intRowHandle, "jibengongzi");   
         if (DBNull.Value != rowJibengongziObj)   
         {   
             FocusedRow_jibengongzi = Convert.ToDecimal(rowJibengongziObj);   
         }   
      }  
   //当数据发生变化时执行 
        private void gridView1_CellValueChanged(object sender, CellValueChangedEventArgs e)
        {
            int intRowHandle = e.RowHandle;
            FocusedRow_bumen = Convert.ToString(gridView1.GetRowCellValue(intRowHandle, "bumen"));
            FocusedRow_xingming = Convert.ToString(gridView1.GetRowCellValue(intRowHandle, "xingming"));
            //FocusedRow_jibengongzi = Convert.ToDecimal(gridView1.GetRowCellValue(intRowHandle, "jibengongzi"));
            object rowJibengongziObj = gridView1.GetRowCellValue(intRowHandle, "jibengongzi");
            if (DBNull.Value != rowJibengongziObj)
            {
                FocusedRow_jibengongzi = Convert.ToDecimal(rowJibengongziObj);
            }
         } view plaincopy to clipboardprint?
//设置焦点行的焦点单元格的位置   
ColumnView view = (ColumnView)gridControl_Gongzi.FocusedView;   
view.FocusedColumn = view.Columns["bumen"];  
//设置焦点行的焦点单元格的位置
ColumnView view = (ColumnView)gridControl_Gongzi.FocusedView;
view.FocusedColumn = view.Columns["bumen"]; view plaincopy to clipboardprint?
//当焦点行发生改变时执行 获取选中焦点行id   
       private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)   
       {   
           int intRowHandle = e.FocusedRowHandle;   
  
           object rowIdObj = gridView1.GetRowCellValue(intRowHandle, "id");   
  
           if (DBNull.Value != rowIdObj)//做个判断否则获取不到id后报错   
           {   
               FocusedRow_id = Convert.ToInt32(rowIdObj);   
           }   
       }  
 //当焦点行发生改变时执行 获取选中焦点行id
        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            int intRowHandle = e.FocusedRowHandle;
 
            object rowIdObj = gridView1.GetRowCellValue(intRowHandle, "id");
 
            if (DBNull.Value != rowIdObj)//做个判断否则获取不到id后报错
            {
                FocusedRow_id = Convert.ToInt32(rowIdObj);
            }
        }   
 
 view plaincopy to clipboardprint?
//焦点行的FocusedHandle为:   
 FocuseRow_Handle = -999998;   
//获取焦点行的handle   
ColumnView newview = (ColumnView)gridControl_Gongzi.FocusedView;   
  
                        FocuseRow_Handle = newview.FocusedRowHandle;   
//回车添加新行   
代码
  private void gridView1_KeyPress(object sender, KeyPressEventArgs e)   
           
        {   
            
if (e.KeyChar == 13)   
            {   
                ColumnView view 
= (ColumnView)gridControl_Gongzi.FocusedView;   
                
if(view.IsLastRow)   
                {   
                    
if (FocuseRow_Handle == 0)   
                    {   
                        gridView1.AddNewRow();   
                           
                        ColumnView newview 
= (ColumnView)gridControl_Gongzi.FocusedView;   
                           
                        newview.FocusedColumn 
= newview.Columns["bumen"];//定位焦点网格的位置   
                           
                        FocuseRow_Handle 
= newview.FocusedRowHandle;//获取新焦点行的FocuseRowHandle 并初始化全局变量FocuseRow_Handle供保存操作时判断是update还是insert    
                    }

 

posted @ 2010-01-30 06:40  滴水铭心  阅读(1889)  评论(0编辑  收藏  举报