RE: DataGrid multi selection

Tech-Archive recommends: Fix windows errors by optimizing your registry



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.
>
>
.



Relevant Pages

  • Re: Asp.net Dropdownlist selected index in changed
    ... private void BindSectionDropDownlist() ... private void section_DropDownList_SelectedIndexChanged(object sender, ... to populate lists 2 and 3 with until a selection has been made with list 1. ...
    (microsoft.public.dotnet.framework.aspnet)
  • How to get the messageclass of a selected item in Outlook
    ... private Outlook.Inspectors _inspectors; ... private void ThisAddIn_Startup(object sender, System.EventArgs ... I tried different things with Outlook.Selection selection; ...
    (microsoft.public.office.developer.com.add_ins)
  • Re: Indexing Services from .NET??
    ... This sample code: ... >> private void InitializeComponent() ... >> private void CheckBox1_CheckedChanged(object sender, ... >> search (buf); ...
    (microsoft.public.inetserver.indexserver)
  • 301 redirect to new domain
    ... I'm trying to use this sample code on my default.aspx page: ... <script runat="server"> ... private void Page_Load(object sender, System.EventArgs e) ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Listview, reselect old selection C#
    ... private void listView1_MouseDown(object sender, MouseEventArgs e) ... > I've got a listview on a form in report style. ... > user clicks on one of these items I want the selection to revert back ...
    (microsoft.public.dotnet.languages.csharp)