• First Click on Combox in DataGridView without Reaction


    Here is the demo code.

    public Form1()
    {
        InitializeComponent();
        view.viewName = "A";
        view.cameraName = "B";
        view.imageSize = "10";
        view.frameRate = 12;
        view.exposureTime = 34;
    }
    
    struct View
    {
        public string viewName;
        public string cameraName;
        public string imageSize;
        public double frameRate;
        public double exposureTime;
    }
    
    View view;
    
    static string MakeExposureTime(double time)
    {
        return time.ToString();
    }
    
    private void Form1_Load(object sender, EventArgs e)
    {
        int row = dataGridView_ActiveJob.Rows.Add(view.viewName, view.cameraName, view.imageSize, view.frameRate.ToString(), Form1.MakeExposureTime(view.exposureTime), "0%");
        DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)(dataGridView_ActiveJob.Rows[row].Cells["Rotate"]);
        cell.DataSource = new string[] { "0", "90", "180", "270" };
        dataGridView_ActiveJob.AllowUserToAddRows = false;
    }
    View Code

    Solution:

    The effect of the first click is to make the cell get the focus, you can avoid it by the following steps.

    First, set the property "EditMode" of the DataGridView control to "EditOnEnter".

     

    Second, add the "CellClick" event to the DataGridView. The specific code is as follows.

    private void dataGridView_ActiveJob_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        if (e.ColumnIndex >= 0 && e.RowIndex >= 0 && dataGridView_ActiveJob[e.ColumnIndex, e.RowIndex] != null && !dataGridView_ActiveJob[e.ColumnIndex, e.RowIndex].ReadOnly)
        {
            DataGridViewComboBoxColumn comboBoxColumn = dataGridView_ActiveJob.Columns[e.ColumnIndex] as DataGridViewComboBoxColumn;
            if (comboBoxColumn != null)
            {
                dataGridView_ActiveJob.BeginEdit(true);
                DataGridViewComboBoxEditingControl comboBoxEditingControl = dataGridView_ActiveJob.EditingControl as DataGridViewComboBoxEditingControl;
                if (comboBoxEditingControl != null)
                {
                    comboBoxEditingControl.DroppedDown = true;
                }
            }
        }
    }
    View Code
  • 相关阅读:
    牛客训练三:处女座的训练(贪心)
    牛客训练二:处女座的砝码(数学题)
    牛客训练二:处女座的签到题(STL+精度+三角形求面积公式)
    牛客训练:小a与黄金街道(欧拉函数+快速幂)
    数论二(快速幂)
    数论一(欧拉函数+费马小定理)
    字典树模板
    springboot在idea的RunDashboard如何显示出来
    网关集成Swagger出现404错误
    maven一直加载2.0.0.M7 的 config server 失败
  • 原文地址:https://www.cnblogs.com/jizhiqiliao/p/9915011.html
Copyright © 2020-2023  润新知