老赵摄 发表于 2022-8-29 23:05:19

如何在程序中调用C1flexgrid的鼠标双击事件

在程序中已经在某列绑定了c1MultiSelect为编辑器,现在想调用c1flexgrid的鼠标双击事件来打开c1MultiSelect。请问应该怎么处理?

Richard.Ma 发表于 2022-8-30 09:35:10

在MouseDoubleClick事件中加上下面的代码看看

      private void C1FlexGrid1_MouseDoubleClick(object sender, MouseEventArgs e)
      {
            c1FlexGrid1.StartEditing(c1FlexGrid1.Row, c1FlexGrid1.Col);
      }

老赵摄 发表于 2022-8-30 15:49:00

马老师,可能的帖子交待不清楚。我的想法是:点击右键菜单,1、如果能直接弹出c1MultiSelect的下拉多选框则更好,哪就可以不用鼠标双击事件了。2,如果1实现不了,则通过引发c1flexgrid的鼠标双击事件的代码,进而弹出c1MultiSelect的下拉多选框。反正我的目的是弹出下拉多选框。不知,我这样的想法如何能实现

Richard.Ma 发表于 2022-8-30 18:05:20

定义变量HitTestInfo info;

右键点击事件中,通过c1FlexGrid1.HitTest(e.X,e.Y);获取到HitTestInfo(包含行列信息)
      private void C1FlexGrid1_MouseClick2(object sender, MouseEventArgs e)
      {
            if(e.Button==MouseButtons.Right)
                info = c1FlexGrid1.HitTest(e.X,e.Y);
      }

在menuitem点击事件中再startediting
var mi = new MenuItem();
            
            mi.Click += new EventHandler((s,e) =>
            {
               
                c1FlexGrid1.StartEditing(info.Row, info.Column);
            });
            var cm = new ContextMenu();
            cm.MenuItems.Add(mi);
            c1FlexGrid1.ContextMenu = cm;

老赵摄 发表于 2022-8-30 22:18:05

不好意思,我给你Demo。

老赵摄 发表于 2022-8-30 22:20:36

我的程序是VB.net的,麻烦您给看下,问题出在哪里。谢谢Imports C1.Win.C1FlexGrid

Public Class Form1
    Private Info As HitTestInfo

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load


      C1FlexGrid1.Rows.Count = 7
      C1FlexGrid1.Cols.Count = 6
      C1FlexGrid1.Rows.MinSize = 30

      C1FlexGrid1.Cols(3).Width = 250
      C1FlexGrid1.Cols(3).Editor = C1MultiSelect1

      C1MultiSelect1.Separator = "/"


      C1FlexGrid1(1, 3) = ""

      C1FlexGrid1(2, 3) = "张三/李四/"

      C1FlexGrid1(3, 3) = "李小二/张三/"

      C1FlexGrid1(4, 3) = "许忠义/张三/李四/"



      C1FlexGrid1.Cols(5).Width = 250
      C1FlexGrid1.Cols(5).Editor = C1CheckList1

      C1FlexGrid1(1, 5) = "李小二/张三/李四/"

      C1FlexGrid1(2, 5) = "张三/李四/"

      C1FlexGrid1(3, 5) = "李小二/张三/"

      C1FlexGrid1(4, 5) = "许忠义/张三/李四/"

      C1FlexGrid1.ContextMenuStrip = ContextMenuStrip1

    End Sub

    Private Sub C1FlexGrid1_MouseClick(sender As Object, e As MouseEventArgs) Handles C1FlexGrid1.MouseClick
      ' If (e.Button = Windows.Forms.MouseButtons.Left) Then
      Info = C1FlexGrid1.HitTest(e.X, e.Y)
      'MsgBox("Info.e.X=" & Info.X & Chr(13) & "Info.e.Y=" & Info.Y & Chr(13) & "Info.Row=" & Info.Row & Chr(13) & "Info.Col=" & Info.Column)
      ' End If

    End Sub

    Private Sub C1FlexGrid1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles C1FlexGrid1.MouseDoubleClick


      If C1FlexGrid1.Col = 3 Then


            If IsNothing(C1FlexGrid1(C1FlexGrid1.Row, 3)) Then
                C1MultiSelect1.Text = ""
            Else
                C1MultiSelect1.Text = C1FlexGrid1(C1FlexGrid1.Row, 3)
            End If


            Dim cText As String = C1MultiSelect1.Text
            For Each item In C1MultiSelect1.Items
                If cText.Contains(item.Value.ToString) Then
                  item.Selected = True
                End If
            Next

      End If

      If C1FlexGrid1.Col = 5 Then
            C1CheckList1.Height = 100
            Dim cText As String = C1FlexGrid1(C1FlexGrid1.Row, 5)
            For Each item In C1CheckList1.Items
                If cText.Contains(item.Value.ToString) Then
                  item.Selected = True
                End If
            Next

      End If

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click      '充填下拉复选框内容

      Dim kk As String() = "李小二|张三|李四|许忠义|尚飞".Split("|")
      Dim i%

      For i = 0 To kk.Count - 1
            C1MultiSelect1.Items.Add(kk(i))
            C1CheckList1.Items.Add(kk(i))
      Next

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click   '清除下拉复选内容
      If C1MultiSelect1.Items.Count > 0 Then C1MultiSelect1.Items.Clear()
    End Sub


    Private Sub 人员安排ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 人员安排ToolStripMenuItem.Click

      C1FlexGrid1.StartEditing(C1FlexGrid1.Row, 3)


    End Sub
End Class


Richard.Ma 发表于 2022-8-31 10:29:57

这里应该是Right右键点开菜单的

页: [1]
查看完整版本: 如何在程序中调用C1flexgrid的鼠标双击事件