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
close icon

Unexpected DataBoundGrid Cell Editing Behavior

In the DataBoundGrid: 1) When editing within a cell, press the delete key with the intent to delete some characters in the cell, however, the entire row is deleted. 2) In a cell with drop down multi-column GridList control that has both a display memeber and value, try backspacing over the characters. Sometimes, the bacspaces until just three characters remain and then stops. Other times, the backspace doesn''t work at all unless the characters are highlighted first. As described in 1), if you press anytime it deletes the row as described in 1), above. Do you see this same behavior? Do I have to trap events to change this? Thanks to the Syncfusion Team --Kenton

4 Replies

AD Administrator Syncfusion Team June 5, 2004 10:53 AM UTC

1) Do you have ListBoxSelectionMode set to something other than none? If so, rows will be selected in this mode, and if you press the delete key with rows selected, the grid deletes them. Try turning off the selection mode and I think you will see teh delete key work the way you expect. If you want to keep the selection mode, then you can handle the RowsDeleting event, cancel the delete and delete the text yourself. Here is a rough snippet that you may have to adjust for different celltypes in your grid.
private void gridDataBoundGrid1_RowsDeleting(object sender, Syncfusion.Windows.Forms.Grid.GridRowRangeEventArgs e)

{

	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;

	if(cc.IsEditing)

	{

		e.Cancel = true;

		GridTextBoxControl gtbc = cc.Renderer.Control as GridTextBoxControl;

		if(gtbc != null)

			gtbc.SelectedText = "";

	}

}
2) Do you have the DropDownStyle set to AutoComplete? If so, you are forcing the grid to autocomplete word after the backspace which will likely be the same selection. Try setting the DropDownStyle to Editiable. That will still autocomplete, but also lets you type values not in the list whic means it will let you backspace over text even if there is no match.


KH Kenton Hensley June 5, 2004 12:23 PM UTC

Smack-on on both counts! 1) Regarding Multi-selection mode, I was under the impression that multi-select for ListBoxSelectionMode had to be on to allow you to select rows. Now I see that this is aimed at selecting multiple ranges of cells. With ListBoxSelectionMode = None and using the row selectors in Column[0], you are still able to select multiple rows. I do not need to allow selection of muliple cell ranges, just multiple row ranges. 2) Setting to editable provides the required behavior. Thank you very much Clay, --Kenton


TN Tim Neumark October 22, 2007 02:21 PM UTC

I don't think this works completely. This implementation deletes the entire contents of the cell; I only want to delete a few letters.

Cell value:
- ABCDEFGH

I want to delete "D". How can I do it? With your method, the whole cell or the whole row is deleted. I want to delete one letter!

If nothing else, it would be helpful to get the position of the cursor within the cell so that I could just modify the index of the string.

Please help! Thanks


RA Rajagopal Syncfusion Team December 29, 2007 12:10 AM UTC

Hi Tim,

Please try the following code in the RowsDeleting event of the GridDataBoundGrid, this will help you in deleting only the character to the right when the delete key is pressed.

void gridDataBoundGrid1_RowsDeleting(object sender, GridRowRangeEventArgs e)
{
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
if (this.gridDataBoundGrid1.Model.Selections.Ranges.ActiveRange.IsRows && cc.IsEditing)
{
e.Cancel = true;
GridTextBoxCellRenderer cr = cc.Renderer as GridTextBoxCellRenderer;
if (cr != null)
{
cr.TextBox.Select(cr.TextBox.SelectionStart, 1);
cr.TextBox.Text = cr.TextBox.Text.Replace(cr.TextBox.SelectedText, "");
cr.TextBox.SelectionStart = cr.TextBox.TextLength;
}
}
}

Let us know if you have any other questions.

Thanks for using Syncfusion Products.

Regards,
Rajagopal


Loader.
Live Chat Icon For mobile
Up arrow icon