This example creates a helper class that allows you to select multiple data rows without pressing the CTRL key. Clicking on a data row toggles its selection state.
Files to Review
Documentation
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
C#using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.Utils;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private DataTable CreateTable(int RowCount)
{
DataTable tbl = new DataTable();
tbl.Columns.Add("Name", typeof(string));
tbl.Columns.Add("ID", typeof(int));
tbl.Columns.Add("Number", typeof(int));
tbl.Columns.Add("Date", typeof(DateTime));
for (int i = 0; i < RowCount; i++)
{
tbl.Rows.Add(new object[] {string.Format("Name{0}", i), i, 3 - i, DateTime.Now.AddDays(i)});
}
return tbl;
}
public Form1()
{
InitializeComponent();
gridControl1.DataSource = CreateTable(20);
MultiSelectionHelper TempMultiSelectionHelper = new MultiSelectionHelper(gridView1);
}
}
}
C#using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.Utils;
namespace WindowsApplication1
{
public class MultiSelectionHelper
{
private GridView _GridView;
public MultiSelectionHelper(GridView gridView)
{
_GridView = gridView;
InitProperties();
SubscribeEvents();
}
private void InitProperties()
{
_GridView.OptionsBehavior.Editable = false;
_GridView.OptionsSelection.MultiSelect = true;
_GridView.OptionsSelection.EnableAppearanceFocusedCell = false;
_GridView.FocusRectStyle = DrawFocusRectStyle.None;
}
private void SubscribeEvents()
{
_GridView.MouseDown += _GridView_MouseDown;
}
private void _GridView_MouseDown(object sender, MouseEventArgs e)
{
OnMouseDown(e);
}
private void OnMouseDown(MouseEventArgs e)
{
GridHitInfo hi = _GridView.CalcHitInfo(e.Location);
if (!hi.InRow)
{
return;
}
_GridView.FocusedRowHandle = hi.RowHandle;
_GridView.FocusedColumn = hi.Column;
_GridView.InvertRowSelection(hi.RowHandle);
DXMouseEventArgs.GetMouseArgs(e).Handled = true;
}
}
}