Ticket Q96719
Visible to All Users

Activating a button control in multiselect mode

created 17 years ago

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

Answers

created 17 years ago

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

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.