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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Setting a combobox to editable

Thread ID:

Created:

Updated:

Platform:

Replies:

60535 May 7,2007 07:27 PM UTC May 9,2007 07:09 PM UTC WinForms 4
loading
Tags: GridControl
Chris
Asked On May 7, 2007 07:27 PM UTC

Hello,

I'm trying to use the following code to set a combobox cell to editable mode. It seems fairly straightforward, but it's stuck in autocomplete mode. Does anything jump out at you?

[Note: It's in a loop that handles the styles for each of the columns in my grid. I've stepped through the code and the nested 'if' statement that assigns the DropDownStyle is actually firing]

if (mapItem.PresentStyle.StartsWith("Combo"))
{
colStyleInfo.CellType = "ComboBox";

if (mapItem.PresentStyle.ToUpper() == "COMBOBOXEDITABLE")
colStyleInfo.DropDownStyle = Syncfusion.Windows.Forms.Grid.GridDropDownStyle.Editable;
}

_gridOrders.ColStyles[i] = colStyleInfo;
}

haneefm [Syncfusion]
Replied On May 7, 2007 08:41 PM UTC

Hi Chris,

By default the GridDropDownStyle is set to Editable, it allows to edit as well as make use of the AutoComplete feature and this is the expected behavior. One way to turn off this behavior would be to handle the CurrentCellKeyPress event and analyze the character that is pressed and append it to the current text. Below are the code snippets.

string val = "";
void gridDataBoundGrid1_CurrentCellKeyPress(object sender, KeyPressEventArgs e)
{
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
if (cc.Renderer.StyleInfo.CellType == "CustomGridDropDownGridListControl")
{
val += e.KeyChar.ToString();
object state = cc.Renderer.GetEditState();
cc.Renderer.ControlText = val;
cc.Renderer.SetEditState(state);
GridTextBoxCellRenderer tr = (GridTextBoxCellRenderer)cc.Renderer;
tr.TextBox.SelectionStart = tr.TextBox.TextLength;
cc.BeginEdit();
e.Handled = true;
}
}

void gridDataBoundGrid1_CurrentCellValidating(object sender, CancelEventArgs e)
{
val = "";
}


Best regards,
Haneef

Chris
Replied On May 9, 2007 03:41 PM UTC

Hi Haneef,

There might be a slight misunderstanding. There are two behaviors I'd like to get from the combobox. Sometimes I want autocomplete where the cell limits the user's input to only those items in the drop-down list. Other times I would like the user to be able to type in a value that doesn't exist in the drop-down list.

The autocomplete functionality works fine, but I can't seem to get the combobox to accept character input from the user that doesn't correspond to an item in the drop-down list.

My understanding was that by setting the cell's dropdown style to editable then I would be allowing the user to enter characters freely into the cell.

I can't seem to get that to work. I've set the cell to dropdownstyle.editable and set AllowEnter to true, but it still won't accept character input from the user, unless the user types in an entry that already exists in the drop-down list. It just ignored those characters.

I've checked the appropriate events and I'm not handling the user input anywhere, so there doesn't seem to be a reason why it would be ignored.

Any ideas?

Chris



>Hi Chris,

By default the GridDropDownStyle is set to Editable, it allows to edit as well as make use of the AutoComplete feature and this is the expected behavior. One way to turn off this behavior would be to handle the CurrentCellKeyPress event and analyze the character that is pressed and append it to the current text. Below are the code snippets.

string val = "";
void gridDataBoundGrid1_CurrentCellKeyPress(object sender, KeyPressEventArgs e)
{
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
if (cc.Renderer.StyleInfo.CellType == "CustomGridDropDownGridListControl")
{
val += e.KeyChar.ToString();
object state = cc.Renderer.GetEditState();
cc.Renderer.ControlText = val;
cc.Renderer.SetEditState(state);
GridTextBoxCellRenderer tr = (GridTextBoxCellRenderer)cc.Renderer;
tr.TextBox.SelectionStart = tr.TextBox.TextLength;
cc.BeginEdit();
e.Handled = true;
}
}

void gridDataBoundGrid1_CurrentCellValidating(object sender, CancelEventArgs e)
{
val = "";
}


Best regards,
Haneef

Chris
Replied On May 9, 2007 06:05 PM UTC

Also, I'm having a hard time hunting down the bug because I can't seem to get visibility of the CellStyles array at a breakpoint. If I set a breakpoint within, say, the CurrentCellKeyDown event, if I navigate to the cellstyles array I can't see any of the cell style info. I'm not sure how to find out if the dropdownstyle is somehow getting overwritten.

Do you have any suggestions on troubleshooting runtime cellstyle issues in visual studio?

Thanks!

Chris

Chris
Replied On May 9, 2007 07:09 PM UTC

Alright, I figured this one out too. It turns out that 'AllowEnter' doesn't allow the user to enter that cell, it allows the user to include an enter key in the cell value. Of course if I read the property description I would have known that hours ago.

C

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;