We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Deleting multiple records in grouping grid

1. I use GridSelectionFlags.Any for my grouping grid. I have noticed that if you select a row range (as opposed to a cell range) and then press the delete button, all the selected rows are deleted. I would like to also implement this behaviour when the user presses a button. Is there a simple way to trigger this behaviour from code? If there is no direct way to trigger this behaviour, I guess it can be done using the info in TableControl.Selections.GetSelectedRows. However, I found it difficult to figure out how to get from the selection indexes to the actual records. If there are no easier way, can you give an example of how to do this? 2. Another question. How can I limit the number of characters in a text column? (I have a database column that allows, say, max 16 characters. If the user enters a longer text it is truncated without warning when it is saved to the DB. I would thus like prevent the user from entering more characters in the grid.)

4 Replies

AD Administrator Syncfusion Team May 4, 2005 05:21 PM UTC

The simplest thing to do is to send the Delete key to the grid using SendKeys if that will work for you. Here is a button handler that tries this.
private void button1_Click(object sender, System.EventArgs e)
{
	if(this.gridGroupingControl1.TableModel.Selections.GetSelectedRows(true, false).Count > 0)
	{
		this.gridGroupingControl1.Focus();
		SendKeys.Send("{DEL}");
	}
}
To control the input length of a TextBox cell, try setting: this.gridGroupingControl1.TableDescriptor.Columns["Col1"].Appearance.AnyRecordFieldCell.MaxLength = 15;


AD Administrator Syncfusion Team May 4, 2005 07:38 PM UTC

I was not able to make this work. It seems like the grid never receives the key. When I sent the delete key using the code above, the TableControlCurrentCellKeyDown event handler was never called. On the other hand, if I press the Del key from the keyboard (or any other key) the TableControlCurrentCellKeyDown is called. I also tried to send the Del key to a text box on the same form with the code and this workes fine. Any ideas why this doesn''t work for the grouping grid? The solution for max text length worked fine. Thanks.


AD Administrator Syncfusion Team May 4, 2005 07:46 PM UTC

Since you are doing this from a menu item, try calling Validate on the form before sending the key. this.Validate();// here this refers to the form this.gridGroupingControl1.Focus(); SendKeys.Send("{DEL}");


AD Administrator Syncfusion Team May 5, 2005 07:42 AM UTC

I think I found the solution. The problem was with the Focus statement. Setting the focus to the TableControl instead of the GridControl itself solved the problem (don''t ask me why!): this.gridControl1.TableControl.Focus();

Loader.
Live Chat Icon For mobile
Up arrow icon