找回密码
 立即注册

QQ登录

只需一步,快速开始

多维时空
论坛元老   /  发表于:2013-5-29 15:49  /   查看:7914  /  回复:8
请问如何在c1FlexGrid表格某一列插入只带文字的按钮以及如何进行该按钮的触发事件?菜鸟求助~

8 个回复

倒序浏览
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2013-5-29 17:38:00
沙发
回复 1楼多维时空的帖子

多维时空 你好

在以下目录中提供了FlexGrid实现各种 Editor 的演示程序,你可以参考:C:\Users\用户名\Documents\ComponentOne Samples\Studio for WinForms\C1FlexGrid\CS\CustomEditors
回复 使用道具 举报
多维时空
论坛元老   /  发表于:2013-5-29 22:38:00
板凳
回复 2楼dof的帖子

我看了,可是我想要的是按钮在单元格中间那种,如第一张图;不是如第二张图只在右下角的那种小按钮,有没有类似设置单元格图片时的方法如c1FlexGrid1.SetCellImage(1, 0, Image.FromFile(Application.StartupPath + "\\b.ico"));望指教!!!
或者说可不可以让第二张图的按钮能够以合适的大小放在单元格中间位置


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2013-5-30 17:39:00
地板
可以使用以下代码,但是有一点需要注意,如果你FlexGrid中数据行数过多不建议采用该方法,你可以设置该单元显示为一个图片,如何判断该单元格的单击事件:

  1.     public partial class Form2 : Form
  2.     {
  3.         public Form2()
  4.         {
  5.             InitializeComponent();
  6.         }

  7.         private void Form2_Load(object sender, EventArgs e)
  8.         {           
  9.             c1FlexGrid1.DrawMode = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw;
  10.             c1FlexGrid1.OwnerDrawCell += c1FlexGrid1_OwnerDrawCell;
  11.             c1FlexGrid1.Rows.Count = 20;
  12.         }

  13.         void c1FlexGrid1_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e)
  14.         {
  15.             if (e.Col == 2 && e.Row > 0)
  16.             {
  17.                 Button button = new Button();
  18.                 button.Name = string.Format("FG_Button_{0}",e.Row);
  19.                 button.Text = "修改";
  20.                 button.Click += button_Click;
  21.                 c1FlexGrid1.Controls.Add(button);

  22.                 button.Location = new Point(e.Bounds.Left, e.Bounds.Top);
  23.                 button.Size = new Size(e.Bounds.Width, e.Bounds.Height);
  24.             }
  25.         }

  26.         void button_Click(object sender, EventArgs e)
  27.         {
  28.             
  29.         }
  30.     }
复制代码
回复 使用道具 举报
多维时空
论坛元老   /  发表于:2013-5-30 21:38:00
5#
回复 4楼dof的帖子

可是有一个问题是,窗口加载后button不会直接显示,如图一;需要单独点击单元格来依次出现button,如图二;或者是要拖动一下窗体button才能全部显示出来,如图三;可不可以窗体加载时所需button就能全部加载并显示出来?





本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2013-5-31 11:17:00
6#
该功能我建议你采用显示图片的方式来实现,比如以下代码:
  1.     private void Form5_Load(object sender, EventArgs e)
  2.     {
  3.         c1FlexGrid1.Rows.Count = 20;
  4.         c1FlexGrid1.Cols[1].Width = 20;
  5.         c1FlexGrid1.Cols[1].ImageAlign = C1.Win.C1FlexGrid.ImageAlignEnum.CenterCenter;

  6.         for (int row = 1; row < c1FlexGrid1.Rows.Count; row++)
  7.         {
  8.             c1FlexGrid1.SetCellImage(row, 1, Image.FromFile("edit.jpg"));                       
  9.         }

  10.         c1FlexGrid1.MouseClick += new MouseEventHandler(c1FlexGrid1_MouseClick);
  11.     }

  12.     void c1FlexGrid1_MouseClick(object sender, MouseEventArgs e)
  13.     {
  14.         MessageBox.Show(string.Format("({0},{1})",c1FlexGrid1.Row,c1FlexGrid1.Col));
  15.     }
复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2013-5-31 11:55:00
7#
详细代码可以查看这篇博客文章:在 C1FlexGrid 中添加编辑和删除按钮
回复 使用道具 举报
多维时空
论坛元老   /  发表于:2013-5-31 12:49:00
8#
回复 7楼dof的帖子

那好吧,看来只能这样了。。。多谢~~
回复 使用道具 举报
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2013-5-31 14:53:00
9#
Ok,不客气
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部