设置表格控件的布局样式|定制新增插入删除按钮|NavigatorCustomButton属性
作者:C/S框架网  发布日期:2018-12-07 19:24:13
  设置表格控件的布局样式|定制新增插入删除按钮|NavigatorCustomButton属性



C# Code:

/// <summary>
/// 设置表格控件的布局样式,定制新增插入删除按钮
/// </summary>
/// <param name="grid">表格组件</param>
/// <param name="allowEdit">允许修改</param>
/// <param name="add">允许新增</param>
/// <param name="insert">允许插入</param>
/// <param name="delete">允许删除</param>
public static void SetGridControlLayout(GridControl grid, bool allowEdit, bool add, bool insert, bool delete)
{
   ControlNavigatorButtons btns = grid.EmbeddedNavigator.Buttons;
   
   grid.BeginInit();
   grid.EmbeddedNavigator.ButtonStyle = BorderStyles.Office2003;
   grid.UseEmbeddedNavigator = true;
   btns.Append.Visible = false;
   btns.CancelEdit.Visible = false;
   btns.Edit.Visible = false;
   btns.Remove.Visible = false;
   btns.EndEdit.Visible = false;
   btns.NextPage.Visible = false;
   btns.PrevPage.Visible = false;
   
   ((GridView)grid.Views[0]).OptionsBehavior.Editable = allowEdit; //允许编辑状态
   
   if (allowEdit)//增加三个自定义按钮(ADD,INSERT,DELETE)
   {
      ImageList img = new ImageList();
      img.Images.Add(Globals.LoadImage("16_Add.ico"));//加载本地图标文件
      img.Images.Add(Globals.LoadImage("16_Insert.ico"));
      img.Images.Add(Globals.LoadImage("16_Delete.ico"));
      grid.EmbeddedNavigator.Buttons.ImageList = img;
      
      btns.CustomButtons.Clear();
      if (add)
      {
         NavigatorCustomButton btnDtlAdd = new NavigatorCustomButton((int)DetailButtons.Add, "新增记录");
         btns.CustomButtons.AddRange(new NavigatorCustomButton[] { btnDtlAdd });
      }
      
      if (insert)
      {
         NavigatorCustomButton btnDtlInsert = new NavigatorCustomButton((int)DetailButtons.Insert, "插入记录");
         btns.CustomButtons.AddRange(new NavigatorCustomButton[] { btnDtlInsert });
      }
      
      if (delete)
      {
         NavigatorCustomButton btnDtlDelete = new NavigatorCustomButton((int)DetailButtons.Delete, "删除记录");
         btns.CustomButtons.AddRange(new NavigatorCustomButton[] { btnDtlDelete });
      }
   }
   grid.EndInit();
}


//来源:C/S框架网(www.csframework.com) QQ:23404761




C# Code:

/// <summary>
/// 加载Debug\Images目录下的的图片
/// </summary>
/// <param name="imgFileName">文件名</param>
/// <returns></returns>
public static Image LoadImage(string imgFileName)
{
   string file = Application.StartupPath + @"\images\" + imgFileName;
   if (File.Exists(file))
   return Image.FromFile(file);
   else
   return null;
}

//来源:C/S框架网(www.csframework.com) QQ:23404761





贴图图片
上一篇 下一篇