简体   繁体   中英

How do i select multiple cells of datagridview without pressing Ctrl key?

I have a datagridview control which i am using to make a weekly schedule.

User can select different time of different days by selecting multiple cells from the gridview.

Problem here is that once the user selects multiple cells for the first time and would like to select more cells , he need to press the Ctrl key from the keyboard which is very difficult for end user to use as in the case if he/she has no keyboard available or he is not aware of pressing Ctrl key.

I have attached a snapshot. Please provide me any solution if you have.

在此处输入图片说明

也许您可以通过DataGridView的CellMouseDownCellMouseMoveCellMouseUp事件来实现。

You can use input simulator for holding Control key and as Wudge mentioned with mouse events you can solve your issue.

http://inputsimulator.codeplex.com/releases/view/37570

private void Form1_Load(object sender, EventArgs e)
        {
            List<Person> mypeople = new List<Person>();
            mypeople.Add(new Person() { Key = 3, Value = "Turgay" });
            mypeople.Add(new Person() { Key = 4, Value = "Hamsi" });
            mypeople.Add(new Person() { Key = 5, Value = "Cabbar" });

            dataGridView1.DataSource = mypeople;


            dataGridView1.MouseEnter += DataGridView1_MouseEnter;
            dataGridView1.MouseLeave += DataGridView1_MouseLeave;
        }

        private void DataGridView1_MouseEnter(object sender, EventArgs e)
        {
            InputSimulator.SimulateKeyDown(VirtualKeyCode.CONTROL);
        }

        private void DataGridView1_MouseLeave(object sender, EventArgs e)
        {
            InputSimulator.SimulateKeyUp(VirtualKeyCode.CONTROL);
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM