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

GridAwareTextBoxes and exclusive combo boxes

Thread ID:

Created:

Updated:

Platform:

Replies:

35954 Oct 17,2005 04:55 AM UTC Oct 17,2005 08:07 AM UTC WinForms 1
loading
Tags: GridControl
Sue Harris
Asked On October 17, 2005 04:55 AM UTC

Hi, I''m getting an exception when the user tries typing in an invalid value in the GridAwareTextBox for an exclusive combo box (details below). What is the best way of handling this problem? Thanks, Sue An unhandled exception of type ''System.ArgumentException'' occurred in system.windows.forms.dll Additional information: ''-1'' is not a valid value for ''length''. The exception is occuring in the OnTextChanged event in GridAwareTextBox where it is trying to set the text box selection when the validation fails. The problem is fairly easily reproducable: Simply add the following code into the FormulaGrid example Load event, and then try to type an invalid value in the grid aware text box for the cell: int col1 = 2; int row1 = 14; this.gridControl1[row1,col1].Format = string.Empty; this.gridControl1[row1,col1].CellType = "ComboBox"; System.Collections.Specialized.StringCollection list = new System.Collections.Specialized.StringCollection(); list.AddRange(Enum.GetNames(typeof(System.DayOfWeek))); this.gridControl1[row1,col1].ChoiceList = list; this.gridControl1[row1,col1].ShowButtons = Syncfusion.Windows.Forms.Grid.GridShowButtons.ShowCurrentCell; this.gridControl1[row1,col1].DropDownStyle = GridDropDownStyle.Exclusive; this.gridControl1[row1,col1].CellValue = System.DayOfWeek.Wednesday;

Administrator [Syncfusion]
Replied On October 17, 2005 08:07 AM UTC

One way you can handle this is to override the OnTextChanged method in a derived GridAwareTextBox and do work there to make sure only list items appear for this type of cell. Here is any initial try at this. Depending upon the exact behavior you want, you might have to add/remove code to handle other such behavior.
public class MyGridAwareTextBox : GridAwareTextBox
{
	protected override void OnTextChanged(EventArgs e)
	{
		GridCurrentCell cc = this.grid.CurrentCell;
		if(cc != null)
		{
			GridStyleInfo style = this.grid.Model[cc.RowIndex, cc.ColIndex];
			if(style.CellType == "ComboBox" && style.DropDownStyle == GridDropDownStyle.Exclusive)
			{
				GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer;
				int found = cr.ListBoxPart.FindStringExact(this.Text);
				if(found == -1)
				{
					found = cr.ListBoxPart.FindString(this.Text);
					if(found == -1)
					{
						this.Text = cc.Renderer.ControlText;
						return;
					}
					else
					{
						int pos = this.SelectionStart;
						this.Text = cr.ListBoxPart.Items[found].ToString();
						this.SelectionStart = pos;
						this.SelectionLength = this.Text.Length - pos;
					}
				}
			}
		}
		base.OnTextChanged (e);
	}

	GridControlBase grid;
	// WireGrid modified to get a reference to the grid.
	public new void WireGrid(GridControlBase grid)
	{
		if (grid != null)
		{
			this.grid = grid;
			base.WireGrid(grid);
		}
	}
}

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

;