Home All Groups Group Topic Archive Search About

datagridview multiselect without keyboard !

Author
17 Apr 2007 9:53 AM
oliharvey
howdy....

in a datagridview - the user can select multiple rows by holding the
Control key down as they click with the mouse.

I am looking for a way to achieve the same result without the use of
the keyboard (I have a touchscreen application).

any ideas? - I'm a bit stuck :)

thanks,
Oli.
Author
17 Apr 2007 2:26 PM
Bryan Phillips
The easiest way might be to toggle rows as selected/unselected when they
click (touch) each row.

--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog:  http://bphillips76.spaces.live.com
Web Site:  http://www.composablesystems.net



Show quoteHide quote
"olihar***@googlemail.com" <olihar***@googlemail.com> wrote in message
news:1176803624.400390.122930@q75g2000hsh.googlegroups.com:

> howdy....
>
> in a datagridview - the user can select multiple rows by holding the
> Control key down as they click with the mouse.
>
> I am looking for a way to achieve the same result without the use of
> the keyboard (I have a touchscreen application).
>
> any ideas? - I'm a bit stuck :)
>
> thanks,
> Oli.
Are all your drivers up to date? click for free checkup

Author
17 Apr 2007 2:43 PM
ClayB
You can try tracking selected rows yourself and toggle the selections
on and off in the CellClick event. You can use the RowPrePaint event
to set the backcolor of selected rows.

            //in form.load
            this.dataGridView1.DefaultCellStyle.SelectionBackColor =
Color.FromArgb(0, Color.Black); //hide normal color
            this.dataGridView1.EditMode =
DataGridViewEditMode.EditProgrammatically;
            this.dataGridView1.CurrentCell = null;

            this.dataGridView1.CellClick += new
DataGridViewCellEventHandler(dataGridView1_CellClick);
            this.dataGridView1.RowPrePaint += new
DataGridViewRowPrePaintEventHandler(dataGridView1_RowPrePaint);



        private List<int> selectedRowIndexes = new List<int>();

        void dataGridView1_RowPrePaint(object sender,
DataGridViewRowPrePaintEventArgs e)
        {
            if (this.selectedRowIndexes.IndexOf(e.RowIndex) > -1)

dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor =
Color.LightBlue;
            else

dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor =
SystemColors.Window;
        }

        void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
        {
            if (this.selectedRowIndexes.IndexOf(e.RowIndex) > -1)
                this.selectedRowIndexes.Remove(e.RowIndex);
            else
                this.selectedRowIndexes.Add(e.RowIndex);
            this.dataGridView1.CurrentCell = null;
        }
==================
Clay Burch
Syncfusion, Inc.

Bookmark and Share