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.
Unfortunately, activation email could not send to your email. Please try again.

Clearing ComboBox on a grid

Thread ID:

Created:

Updated:

Platform:

Replies:

5461 Jul 3,2003 08:57 AM Jul 8,2003 06:27 PM Windows Forms 10
loading
Tags: GridControl
Tim Jackson
Asked On July 3, 2003 08:57 AM

I am having problems with a combobox that I have for a grid. When I clear the text for that cell which has the combobox, the value is treated as 'illegal' since an empty string is not one of the items on the list. I want to keep AutoComplete and make the choices exclusive to the list but I also need to clear the selected item. When the selected text is cleared it has the effect of making the entry invalid, thus disabling entry in the grid until the invalid string is resolved. Is there a easy way to clear this value like in a combox box you would set the selectedindex to -1. thanks! tim

Administrator [Syncfusion]
Replied On July 3, 2003 10:24 AM

> I am having problems with a combobox that I have for a grid. When I clear the text for that cell which has the combobox, the value is treated as 'illegal' since an empty string is not one of the items on the list. I want to keep AutoComplete and make the choices exclusive to the list but I also need to clear the selected item. When the selected text is cleared it has the effect of making the entry invalid, thus disabling entry in the grid until the invalid string is resolved. Is there a easy way to clear this value like in a combox box you would set the selectedindex to -1. > > thanks! > > tim > With 1.6.1, if the cell does not have focus, you can just use an indexer to set it blank and this will blank out the cell. this.gridControl1[5,3].Text = ""; If you want to blank it out typeing, here is a try at it handling the CurrentCellValidating event.
private void gridControl1_CurrentCellValidating(object sender, System.ComponentModel.CancelEventArgs e)
{
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	if(cc.Renderer is GridComboBoxCellRenderer && cc.Renderer.ControlText == "")
	{
		cc.CancelEdit();
	 	this.gridControl1[cc.RowIndex, cc.ColIndex].Text = "";
	}
}

Tim Jackson
Replied On July 7, 2003 03:49 AM

The problem with what you suggest (which is what I am already doing) is that the blank text is treated as in illegal value since "" is not one of the selections in the the drop down combo list. The result is the grid is treating that entry as invalid and because of that, you cannot make a change to any other cell in the grid till it is resolved i.e. a valid non blank selection is made on that combo box. HEEEELPP!!! :) Tim > > With 1.6.1, if the cell does not have focus, you can just use an indexer to set it blank and this will blank out the cell. > > this.gridControl1[5,3].Text = ""; > > If you want to blank it out typeing, here is a try at it handling the CurrentCellValidating event. >
> private void gridControl1_CurrentCellValidating(object sender, System.ComponentModel.CancelEventArgs e)
> {
> 	GridCurrentCell cc = this.gridControl1.CurrentCell;
> 	if(cc.Renderer is GridComboBoxCellRenderer && cc.Renderer.ControlText == "")
> 	{
> 		cc.CancelEdit();
> 	 	this.gridControl1[cc.RowIndex, cc.ColIndex].Text = "";
> 	}
> }
> 
>

Administrator [Syncfusion]
Replied On July 7, 2003 06:38 AM

Attached is a sample.

Jose M. Gonzalez
Replied On July 7, 2003 01:35 PM

I have a similar situation but the ComboBox is containing a collection of objects, if the user deletes the cell value I want to set the cell value to NULL. The following code is giving me an error (Object type cannot be converted to target type) when I try to delete the cell value. private void gridDataBound_CurrentCellDeleting(object sender, System.ComponentModel.CancelEventArgs e) { GridCurrentCell cc = this.gridDataBound.CurrentCell; if(cc.Renderer is GridComboBoxCellRenderer && cc.Renderer.ControlValue != null) { cc.Renderer.Control.Text = String.Empty; gridDataBound[cc.RowIndex, cc.ColIndex].CellValue = null; } }

Administrator [Syncfusion]
Replied On July 7, 2003 02:18 PM

You might try using DBNull.Value insteadof null to see if that will work for you.

Jose M. Gonzalez
Replied On July 7, 2003 03:19 PM

> You might try using DBNull.Value insteadof null to see if that will work for you. > It didn't work. System.ArgumentException: Object type cannot be converted to target type. at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.SaveCellInfo(GridSaveCellInfoEventArgs e) catched at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.SaveCellInfo(GridSaveCellInfoEventArgs e) in :line 0 An unhandled exception of type 'System.ArgumentException' occurred in syncfusion.grid.dll Additional information: Object type cannot be converted to target type.

Administrator [Syncfusion]
Replied On July 8, 2003 05:15 AM

This exception comes from SaveCellInfo method in GridModelDataBinder because you are trying to assing System.DBNull to a class property which is an object. Most of my data sources are BindingList not DataTables, how can I set "null" value instead of "System.DBNull"? THanks

Administrator [Syncfusion]
Replied On July 8, 2003 11:57 AM

I haven't really tried this but I think you could try handling the grid.Model.DataProviderSaveCellInfo event and swap out DBNull as follows: if (e.Style.CellValue is DBNull) e.Style.CellValue = null; Do not change e.Handled so that GridModelDataBinder.SaveCellInfo will still be called afterwards. Stefan

Administrator [Syncfusion]
Replied On July 8, 2003 06:27 PM

NOT IT WORKS!!!! Thanks......

Administrator [Syncfusion]
Replied On July 8, 2003 06:27 PM

NOW IT WORKS!!!! Thanks++++

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.

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.

;