Hi,
We use the XtrGrid control in our application to perform spreadsheet like operations.
We have a gridview containing several columns. And it is necssary to have multiselect mode and block selection enabled in the view to perform copy - paste operations.
To achive this we have set the gridview's OptionSelection.multiselect = true and OptionSelection.multiselectmode = cellselect.
Also rows in the view consists of few buttons hence we use the RepositoryItemButtonEdit controls in such columns.
However my problem is I am not able to activate the button unless it is clicked atleast twice, i.e the button's click event is triggered only after the user cliks on it twice.
Please let me how can i override the default behaviour of such button columns , so that the the click event is triggered on a single click. Also note that we still have to retain the block selection of cells hence I wont be able to set the multiselectmode to "rowselect"
Thanks
Activating a button control in multiselect mode
Answers
Hello Steven,
The solution consist of following tasks: prevent a selection from being lost, activate a cell under the mouse cursor and force the button click event. It can be done in the GridView.MouseDown event handler as shown below:
C#using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.ViewInfo;
using DevExpress.XtraEditors.Controls;
using System.Reflection;
...
private void gridView1_MouseDown(object sender, MouseEventArgs e) {
if((Control.ModifierKeys & Keys.Control) != Keys.Control ) {
GridView view = sender as GridView;
GridHitInfo hi = view.CalcHitInfo(e.Location);
if(hi.InRowCell) {
if(hi.Column.RealColumnEdit.GetType() == typeof(RepositoryItemComboBox)){
view.FocusedRowHandle = hi.RowHandle;
view.FocusedColumn = hi.Column;
view.ShowEditor();
(view.ActiveEditor as ComboBoxEdit).ShowPopup();
//force button click
ButtonEdit edit = (view.ActiveEditor as ComboBoxEdit);
EditHitInfo ehi = (edit.GetViewInfo() as ButtonEditViewInfo).CalcHitInfo(e.Location);
if(ehi.HitTest == EditHitTest.Button)
PerformClick(edit, new ButtonPressedEventArgs(ehi.HitObject as EditorButton));
(e as DevExpress.Utils.DXMouseEventArgs).Handled = true;
}
}
}
}
void PerformClick(ButtonEdit editor, ButtonPressedEventArgs e) {
if(editor == null || e == null) return;
MethodInfo mi = typeof(RepositoryItemButtonEdit).GetMethod("RaiseButtonClick",
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
if(mi != null)
mi.Invoke(editor.Properties, new object[] { e });
}
void PerformClick(ButtonEdit editor, ButtonPressedEventArgs e) {
if(editor == null || e == null) return;
MethodInfo mi = typeof(RepositoryItemButtonEdit).GetMethod("RaiseButtonClick",
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
if(mi != null)
mi.Invoke(editor.Properties, new object[] { e });
}
Thank you,
Paul