RE: DataGrid multi selection
- From: el_sid <el_sid@xxxxxxxxxxxxxxxx>
- Date: Thu, 29 Sep 2005 02:42:02 -0700
Thanks we will give it a try in the next couple of weeks and let you know how
we get on.
""Jeffrey Tan[MSFT]"" wrote:
> Hi el_sid,
>
> Thanks for your post.
>
> To do row selection in cell mouse click operation, we can handle MouseUp
> event of DataGrid, and programmatically select certain row. Please refer to
> the link below:
> "5.11 How can I select the entire row when the user clicks on a cell in the
> row?"
> http://64.78.52.104/FAQ/WinForms/FAQ_c44c.asp#q689q
>
> To implement the Shift/Ctrl multiselection function, we should do the
> selection logic ourselves. I have implemented a sample for Shift key, I
> think you can use this sample code as a reference and implement Ctrl key
> function. Sample code listed below:
> private void dataGrid1_MouseUp(object sender,
> System.Windows.Forms.MouseEventArgs e)
> {
>
> System.Drawing.Point pt = new Point(e.X, e.Y);
> DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);
> if(hti.Type == DataGrid.HitTestType.Cell)
> {
> if((Control.ModifierKeys&Keys.Control)==Keys.Control)
> {
> bool funselect=false;
> for(int i=0;i<al.Count;i++)
> {
> if(hti.Row==(int)al[i])
> {
> funselect=true;
> }
> else
> {
> this.dataGrid1.Select((int)al[i]);
> }
> }
> if(!funselect)
> {
> this.dataGrid1.Select(hti.Row);
> }
> }
> else
> {
> dataGrid1.CurrentCell = new DataGridCell(hti.Row, hti.Column);
> dataGrid1.Select(hti.Row);
> }
> }
> }
>
> //Record original selected rows in arraylist in MouseDown event
> ArrayList al=new ArrayList();
> private void dataGrid1_MouseDown(object sender,
> System.Windows.Forms.MouseEventArgs e)
> {
> al.Clear();
> for(int i=0;i<this.dataGrid1.BindingContext[this.dataGrid1.DataSource,
> this.dataGrid1.DataMember].Count;i++)
> {
> if(this.dataGrid1.IsSelected(i))
> {
> al.Add(i);
> }
> }
> }
> This works well on my side. Hope it helps.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>
>
.
- Follow-Ups:
- RE: DataGrid multi selection
- From: "Jeffrey Tan[MSFT]"
- RE: DataGrid multi selection
- References:
- RE: DataGrid multi selection
- From: "Jeffrey Tan[MSFT]"
- RE: DataGrid multi selection
- Prev by Date: Binding to Checkboxes
- Next by Date: Re: VS2005b2 - I think TextBox.Cut, TextBox.Paste etc should not work with ReadOnly = true...
- Previous by thread: RE: DataGrid multi selection
- Next by thread: RE: DataGrid multi selection
- Index(es):
Relevant Pages
|