Getting user edited Text of sfDataGrid GridComboBoxColumn

Hi,

I have a SfDataGrid with GridComboBoxColumn, DropDownStyle.DropDown and AutoCompleteMode.Suggest. If user enters some text that is not in the list currently, I want to be able to save the new text, preferrably in sfDataGrid.CurrentCellValidating.

I'm sorry if I miss the obvious, but how it is possible to access the user entered text? The only way I found is using custom cell renderer and passing data using TableControl.Text property, but this property seems to be empty on CurrentCellValidating event. Is there a better way?


private void sfDataGrid_CurrentCellEndEdit(object sender, CurrentCellEndEditEventArgs e)
{
if (e.DataColumn.GridColumn.MappingName == "MyColumn")
{
var userText = (e.OriginalSender as SfDataGrid)?.TableControl.Text;
}
}


public class MyGridComboBoxCellRenderer : GridComboBoxCellRenderer
{
protected override void OnEditingComplete(DataColumnBase column, SfComboBox currentRendererElement)
if (column.GridColumn.MappingName == "MyColumn")
{
var userText = column?.GridColumn?.Renderer?.CurrentCellRendererElement?.Text.Trim();
if (userText?.Length > 0)
TableControl.Text = userText;
}
base.OnEditingComplete(column, currentRendererElement);
}
}

3 Replies

MA Mohanram Anbukkarasu Syncfusion Team July 27, 2018 12:44 PM UTC

Hi Tipal, 

Thanks for contacting Syncfusion support. 

You can get the text entered in the ComboBox column by using the CurrentCellRendererElement within the CurrentCellValidating event. Please refer to the below code example and sample from the given location. 
 
Code Example: 
this.sfDataGrid1.CurrentCellValidating += sfDataGrid1_CurrentCellValidating; 
 
void sfDataGrid1_CurrentCellValidating(object sender, CurrentCellValidatingEventArgs e) 
{ 
    var userText = string.Empty; 
    if (e.Column.MappingName == "ShipCityID" && this.sfDataGrid1.CurrentCell.CellRenderer.CurrentCellRendererElement != null) 
        userText = this.sfDataGrid1.CurrentCell.CellRenderer.CurrentCellRendererElement.Text; 
} 

 
Regards, 
Mohanram A. 



T T July 27, 2018 05:12 PM UTC

Thank you very much, that's really helpful!


MA Mohanram Anbukkarasu Syncfusion Team July 30, 2018 05:41 AM UTC

Hi Tipal,  

Thanks for your update. 

We are glad to know that the given solution has resolved your query. Please let us know, If you need any further assistance. 

Regards, 
Mohanram A. 


Loader.
Up arrow icon