all groups > dotnet windows forms > august 2005 >
You're in the

dotnet windows forms

group:

Datagrid multiple select


Datagrid multiple select Gav
8/31/2005 11:08:23 AM
dotnet windows forms: Hi all,

I have put some code in the mouseup event for my datagrid in order to select
the entire row.

Does anybody know how I can get multiple selection to work on my datagrid?

thanks
Gav

Re: Datagrid multiple select Tim_Mac
9/1/2005 12:00:00 AM
hi Gav,
i use the built-in multiple select by just holding down Ctrl while i click
on the left margin of each row.
is this what you want?

tim

--------------------------
blog: http://tim.mackey.ie

Re: Datagrid multiple select Gav
9/6/2005 12:00:00 AM
This is the behaviour that I'm after yes however i do not show the row
headers...

[quoted text, click to view]

Re: Datagrid multiple select Tim_Mac
9/6/2005 6:49:07 PM
hi Gav,
may i ask what is your reason for hiding the row headers?
you are re-creating functionality that is already there, and requiring the
users to learn a non-standard way of selecting a row. most users will be
familiar with the row-header way with excel. you must have a special case
for doing this?
i don't want to be a smart ass but before i/we try and help answer the
question, it would be good to know the reasoning behind your course of
action.
did you try setting the width of the rowheader to 15 pixels? this makes it
much less obtrusive in terms of screen space.

tim

--------------------------
blog: http://tim.mackey.ie

[quoted text, click to view]

Re: Datagrid multiple select Gav
9/8/2005 12:00:00 AM
Why would this be a 'non-standard way of selecting a row' this is how all
listview controls work, look at the inbox of outlook/outlook express you
have a list (with no column headers) which you can hold CTRL and click on
multiple rows to select them.

I guess I could have looked into making a editable ListView but that seems
like a lot more work because the datagrid looks just the same when you hide
the row headers, caption, set the back colour to white etc, then you already
have a listview look that you can edit.

Gavin


[quoted text, click to view]

Re: Datagrid multiple select Gav
9/8/2005 6:29:27 PM
A good example of what I'm looking for is the Library list in Windows media
player 10...

[quoted text, click to view]

Re: Datagrid multiple select Tim_Mac
9/8/2005 8:04:49 PM
hi Gav,
sorry i didn't know you were using the datagrid to look and behave like a
listview. in the normal datagrid situation, it would be non-standard.

to be honest, i think the listview is the one you want. the WM10 library
list is a listview. you can set LabelEdit = true, View=Details. you've got
your multi-select built in, column sorting, etc.
i couldn't get the items to BeginEdit() reliably on SelectedIndexChanged for
some reason, it would flicker editable and then return to normal. will your
users want to edit the text just by selecting an item in the list, or will
the normal listview renaming functionality be sufficient?

tim

--------------------------
blog: http://tim.mackey.ie


[quoted text, click to view]

Re: Datagrid multiple select Gav
9/12/2005 9:28:04 AM
Sorry to be a pain, I know your trying to help, but I do not like the idea
of doing it this way, you cannot bind a datasource to a listview like you
can a datagrid, that was another reason for me to use datagrids over
listview they are easier to use at design time.

I still would have much prefered an answer to my original question, is it
not possible to caption in the onclick that the ctrl key is being held and
multiple select in that way?

Thanks
Gav

[quoted text, click to view]

Re: Datagrid multiple select Tim_Mac
9/13/2005 7:09:12 PM
hi Gav,
you're right. i should have just trusted that you knew what you wanted!
i got this code to behave as you have described
private void dataGrid1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if((Control.ModifierKeys & Keys.Control) == Keys.Control)
this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
}

interestingly this code in MouseDown wouldn't select the row. also
datagrid_Click didn't fire for clicks inside the cells.

hope this works for you.
tim

Re: Datagrid multiple select Gav
9/15/2005 12:00:00 AM
Thanks for the reply I thought I had been forgotten about for a moment
there...

I have tried this out and all it seems to do is select the whole row that I
click on when I hold down CTRL, it doesn't seem to still keep the selection
on the other rows.

Thanks again
Gav

[quoted text, click to view]

Re: Datagrid multiple select Tim_Mac
9/16/2005 12:00:00 AM
hi Gav,
sorry i thought your original request was just to select the whole row. i
lost track of it with all the posts.

i'm all out of inspiration, except to suggest this control i just found:
http://www.csharphelp.com/archives2/archive341.html. it is an editable
listview control, with Ctrl+click multi select.

if that doesn't work you could try a repost, stating that you have removed
the rowheaders of a datagrid, but want to multi-select using Ctrl + click.

good luck
tim

--------------------------
blog: http://tim.mackey.ie

Re: Datagrid multiple select mikemeamail NO[at]SPAM net2000.ch
9/22/2005 2:24:24 AM
Hi Gav,

I'm actually encountering the same problem as yours, meaning i want to
be able to let users select multiple rows on a datagrid without showing
the
rowheaders with the row selector represented by an arrow.
Could you find any solution to your problem ?
Regards,
Mike

[quoted text, click to view]
Re: Datagrid multiple select Gav
9/23/2005 12:00:00 AM
Sorry Mike, I do not have a solution as of yet, but I will surely let you
know when I do.

Regards
Gav

[quoted text, click to view]

Re: Datagrid multiple select Tim_Mac
9/26/2005 9:35:16 PM
hi gav, did that control not serve your purposes?
http://www.csharphelp.com/archives2/archive341.html
i downloaded and tried it out and it seemed to do what you wanted.

tim

--------------------------
blog: http://tim.mackey.ie

AddThis Social Bookmark Button