Dev GridControl 的使用

1、GridControl的数据绑定

同时将导航条控件DataNavigator ,用BindingSource一同绑定,同时同步绑定对应编辑区

/// <summary>
        /// 初始化表格
        /// </summary>
        private void InitFoodKindGrid()
        {
            FoodKindInit fki = new FoodKindInit();
            DataSet ds = fki.SearchFoodKind(shopID);  //取出门店食品大类列表
            bindingSource_FoodKind.DataSource = ds.Tables[0];    //初始化BindingSource
           dataNavi_Foodkind.Core.DataSource = bindingSource_FoodKind;  //初始化导航条
            BindFoodKindGrid();
        }

        /// <summary>
        /// 填充食品大类表
        /// </summary>
        /// <param name="ds"></param>
        private void BindFoodKindGrid()
        {
            //数据绑定的时候不是绑定BindSource的Datasource属性,而是绑定整个BindSource控件
            gridControl_FoodKind.DataSource = bindingSource_FoodKind;
        }
 

/// <summary>
        /// 初始化界面编辑区
        /// </summary>
        /// <param name="strcon"></param>
        private void InitEditZone()
        {
            txt_KindName.DataBindings.Add("Text", bindingSource_FoodKind, "KindName");
            txt_KindNo.DataBindings.Add("Text", bindingSource_FoodKind, "KindNo");
            txt_BillGroup.DataBindings.Add("Text", bindingSource_FoodKind, "BillGroup");
            txt_BonusPercent.DataBindings.Add("Text", bindingSource_FoodKind, "BonusPercent");
            txt_MaxDiscPercent.DataBindings.Add("Text", bindingSource_FoodKind, "MaxDiscPercent");
            //txt_PrntNo.DataBindings.Add("Text", bindingSource_FoodKind, "PrntNo");
            //选择框这里绑定的属性是EditValue!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            chk_CanChangeAmt.DataBindings.Add("EditValue", bindingSource_FoodKind, "CanChangeAmt"); 
            chk_CanChangeQty.DataBindings.Add("EditValue", bindingSource_FoodKind, "CanChangeQty");
            chk_CanCheck1.DataBindings.Add("EditValue", bindingSource_FoodKind, "CanCheck1");
            chk_CanTouch.DataBindings.Add("EditValue", bindingSource_FoodKind, "CanTouch");
            chk_IsUnitQty.DataBindings.Add("EditValue", bindingSource_FoodKind, "IsUnitQty");
            chk_IsBonus.DataBindings.Add("EditValue", bindingSource_FoodKind, "IsBonus");
            chk_IsFloorSum.DataBindings.Add("EditValue", bindingSource_FoodKind, "IsFloorSum");
            chk_IsProduct.DataBindings.Add("EditValue", bindingSource_FoodKind, "IsProduct");
            chk_IsSaleSort.DataBindings.Add("EditValue", bindingSource_FoodKind, "IsSaleSort");
            //chk_UnKnow.DataBindings.Add("Checked", bindingSource_FoodKind.DataSource, "UnKnow");//输入单位数量 在这里不清楚是对应数据库哪个字段,故不做绑定
        }

 

2、获取表格当前焦点行

方法一:GetFocusedDataRow()

 DataRow dr = gridView1.GetFocusedDataRow();
            if (dr != null)  //判断有无获取到行 在用户把表格数据全部删除的时候dr为null                  2012-8-21增加
            {
                string deptId = dr["DeptID"].ToString();
                if (deptId != "")
                {
                    lookUpE__Dept.EditValue = int.Parse(deptId);  //这里的数值类型必须与绑定的一致 
                }
            }

方法二:FocusedRowHandle()

  string indexStr = gridView1.FocusedRowHandle.ToString(); //获取表格选中的行号
            int index = int.Parse(indexStr); 

 

3、获取某行某列的值  GetRowCellValue();

 modelFeastFood[i].FFoodID = int.Parse(gridView1.GetRowCellValue(i, "FFoodID").ToString());

 4、设置某行某列的值SetRowCellValue();

 gridViewWidthoutFloor.SetRowCellValue(i2, "check", false);

 5、获取选中多行的索引值

 int[] selectedRowIndexs = gridViewGrpOutFood.GetSelectedRows(); //获取选中的行号

 6、设置表格列名居中显示

gridView1_EatingDemandQuery.Columns[i].AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;//设置表格列名居中显示

 7、设置表格数据居中显示

gridView1.Columns[i].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;//数据居中显示

 

posted @ 2012-12-03 15:32  qin孑  阅读(1823)  评论(0编辑  收藏  举报