Is it possible to automatically change GridMultiColumnDropDownList ItemsSource if the user type a code that does not exist?
Hi,
Attachment: Combo_columns_for_grids_3001a5d7.zip
please find here attached an example that I have modified to ask you a question and a video where I better explain my question (Question about GridMultiColumnDropDownList.wmv).
I have a GridMultiColumnDropDownList column that is binded to a collection of Product objects named ProductList.
The user can edit the cells in this column, but by default, if he types a Product Code that does not exist and presses Enter, his changes are not considered since the inserted Code is not found in the underlying collection.
But I'd like, instead, that, if a user types a Code that does not exist in the binded collection, a new Product is automatically created (with a new incremental ID) and added to the ProductList collection. So everything the user types in the column, even if it does not exist as a Code, it is automatically added to the Product collection and Order object is correctly updated with the user's changes.
Is it possible to implement such a behaviour?
Can you suggest me any idea?
Thank you.
Silvio
Attachment: Combo_columns_for_grids_3001a5d7.zip
SIGN IN To post a reply.
3 Replies
SV
Srinivasan Vasu
Syncfusion Team
June 27, 2017 09:41 AM UTC
Hi Silvio,
Sorry for delay caused.
We have checked your query and we have prepared a sample as per your requirement. You can achieve your requirement by customizing the GridCellMultiColumnDropDownRenderer.
Please refer the below code.
|
this.Grid.CellRenderers.Remove("MultiColumnDropDown");
this.Grid.CellRenderers.Add("MultiColumnDropDown", new MultiDropDownRenderer());
public class MultiDropDownRenderer: GridCellMultiColumnDropDownRenderer
{
protected override bool ShouldGridTryToHandleKeyDown(KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
var multiDropDown = (this.CurrentCellRendererElement as SfMultiColumnDropDownControl);
var textBox = multiDropDown.GetType().GetProperty("Editor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(multiDropDown);
var newValue = textBox != null ? (textBox as TextBox).Text : null;
var underlyingItems = (this.DataGrid.DataContext as ViewModel).ProductList;
if (underlyingItems != null)
{
bool newRecord = underlyingItems.Any(x => x.Code == newValue.ToString());
if (!newRecord)
{
underlyingItems.Add(new ProductInfo() { Code = newValue.ToString(), ID = underlyingItems.Count + 1 });
multiDropDown.SelectedItem = underlyingItems.Last();
}
}
}
return base.ShouldGridTryToHandleKeyDown(e);
}
} |
Please download the sample from the below location.
Regards,
Srinivasan
Srinivasan
SI
Silvio
June 28, 2017 09:37 AM UTC
very very helpful!
Thank you!
SV
Srinivasan Vasu
Syncfusion Team
June 29, 2017 01:45 AM UTC
Hi Silvio,
Thanks for your update.
Please let us know if need further asssitance.
Regards,
Srinivasan
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
SI Silvio
- Jun 23, 2017 02:41 PM UTC
- Jun 29, 2017 01:45 AM UTC