Dev里面DataGid控件使用方法之一

    技术2025-07-16  18

    Dev里面DataGid控件使用方法之一 (转)

    1、确认当前正在编辑的单元格的输入this.gridview1.CloseEditor();

    2、保存当前行的值到数据源this.gridview1.UpdateCurrentRow();

    3、通过数据适配器把修改更新到数据库sqlDataAdapter1.Update(myDataSet, "MyTable")//此时直接通过DataAdapter执行Update就可以

    按照1,2,3的步骤执行;也可以通过1,2步骤然后通过Sql实现(2)DataGrid的初始化     gridView1.OptionsView.EnableAppearanceEvenRow = true;     gridView1.OptionsView.EnableAppearanceOddRow = true;     gridView1.OptionsView.ShowFilterPanel = false;     gridView1.OptionsView.ShowGroupPanel = false;     gridView1.OptionsView.ShowGroupPanel=false;     gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;     gridView1.OptionsBehavior.Editable = false;     gridView1.OptionsCustomization.AllowColumnMoving = false;     gridView1.OptionsCustomization.AllowColumnResizing = false;     gridView1.OptionsCustomization.AllowGroup = false;     gridView1.OptionsCustomization.AllowFilter = false;     gridView1.OptionsCustomization.AllowSort = true;(3)获取选中的行 和选中行的字段的内容

    int [] a = this .gridView1.GetSelectedRows(); // 传递实体类过去 获取选中的行 LAA.AssetGuid = this .gridView1.GetRowCellValue(a[ 0 ], " AssetGuid " ).ToString(); // 获取选中行的内容

    (4)以前在windows 自带的控件里面Button控件的相互调用是button1_Click(null,EventArgs.Empty); Dev控件下面是simpleButton1_Click(new object(),new EventArgs());(5)在XtraGrid中如何验证单元格的值 我们在XtraGrid直接输入数据的情况下,如何验证每一个单元格输入的值是否正确呢?有两种方法来实现基于单元格的验证:1、使用RepositoryItem.Validating事件事件的"sender" 必须转换为BaseEdit类型,使用EditValue来获取当前输入的值并进行校验,如果校验不通过,把e.Cancel设置True。这种方法一般用来对内置控件的单元格进行数据验证2、使用 GridView.ValidatingEditor 事件事件的"sender"必须转换为GridView类型,当前列可以从GridView.FocusedColumn属性获得,值可以从e.Value获取,如果校验不通过,需要把e.Valid设置为False.。这种方法一般用于对整个Grid内的文本框进行数据验证在设置完事件之后需要写一个GridView.InvalidValueException 的事件委托:例如:

    private void gridView1_InvalidValueException( object sender, DevExpress.XtraGrid.Views.Base.InvalidValueExceptionEventArgs e) {    e.ThrowException = false;    e.WindowText = "The new value is invalid. Please correct it or press Esc to abandon your changes.";    e.DisplayError = true;}

    (6)barManager的具体设置在增加了barManager控件以后,在[Click Here to add MainMenu] [Click Here to Tool Bar]里面选择[Click Here to Tool Bar] 填写需要新增的工具栏按钮。进入Designer 里面,选择ToolBars    ->Custom 1->OptionsBar 里面进行如下设置:AllowQuickCustomization=falseDrawDragBorder=falseRotateWhenVertical=falseUseWholeRow=True以上4项进行初始化设置(7) 在DataGrid 里面增加状态栏首先在BarManager里面增加StaticText    把新增的barStaticItem 的AutoSize 设置为Spring然后,编写以下代码:

    private void StateCote()         {                       if (gridView1.RowCount!=0)            {                int a=this.gridView1.RowCount;                  barStaticItem1.Caption="当前共有记录:"+a.ToString();                int[] b=this.gridView1.GetSelectedRows();                  b[0]+=1;                  barStaticItem2.Caption="当前选中:"+b[0].ToString();              }            else            {                  barStaticItem1.Caption="当前共有记录:";                  barStaticItem2.Caption="当前选中:";              }                  }          private void gridControl1_Click( object sender, System.EventArgs e)         {              StateCote();          }          private void gridView1_FocusedRowChanged( object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)         {              StateCote();          }

    (9) 双击DataGrid弹出详细信息

    private void gridControl1_DoubleClick( object sender, System.EventArgs e)         {            //双击弹出异常日志描述            if (this.gridView1.RowCount > 0)            {                int[] a=this.gridView1.GetSelectedRows();                string str_GUID=this.gridView1.GetRowCellValue(a[0],"Ex_No").ToString();//获得异常编号                  MessageBox.Show(str_GUID);                  frmExceptionLogDesc dlg=new frmExceptionLogDesc();                   dlg.Text = "异常日志查看";                  dlg.ShowDialog();              }          }

     

    最新回复(0)