This is a migrated thread and some comments may be shown as answers.

ComboBoxColumn

3 Answers 84 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Morghabi
Top achievements
Rank 1
Morghabi asked on 20 Jun 2016, 06:47 AM

I need a ComboBox column initialized with some data and the user can enter new data too when inserting new row into grid. For example, ComboBox column has three items by default Phone, Mobile, Fax, but the user needs to insert new item (e.g., Code). How can I do this?

Here is the code. With this code the user can only select one of the default values of combo column and he/she cannot enter his/her new value into combo column.

DataTable table = new DataTable();
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Value", typeof(string));
var details = db.BatchItemDetails.Where(d => d.BatchItem_Id == _id)
                       .Select(d => new { d.Name, d.Value });
foreach (var row in details)
   table.Rows.Add(row.Name, row.Value);
 
grid.MasterTemplate.AutoGenerateColumns = false;
grid.DataSource = table;
 
GridViewComboBoxColumn name = new GridViewComboBoxColumn();
name.DataSource = (from b in db.Batches
             join i in db.BatchItems on b.Id equals i.Batch_Id
             join d in db.BatchItemDetails on i.Id equals d.BatchItem_Id
             where b.Id == batchId
             orderby d.Name
             select d.Name).Distinct().ToArray(); // string array.
 
name.AutoCompleteMode = AutoCompleteMode.Suggest;
name.DropDownStyle = RadDropDownStyle.DropDown;
name.Name = "Name";
name.FieldName = "Name";
name.HeaderText = "عنوان اطلاعات";
name.Width = 219;
name.TextAlignment = ContentAlignment.MiddleLeft;
grid.Columns.Add(name);
 
grid.Columns.Add("Value", "شرح اطلاعات", "Value");
grid.Columns["Value"].Width = 353;
 
grid.AutoSizeRows = true;

3 Answers, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 20 Jun 2016, 11:50 AM
Hello ,

Thank you for writing.

We have an example in our documentation handling exactly this type of scenario: Allow end-users to add items to DropDownListEditor.

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
0
Morghabi
Top achievements
Rank 1
answered on 21 Jun 2016, 07:51 AM
The article is so complex for me that am a beginner in C#. Please clarify the article for me. Thanks.
0
Accepted
Hristo
Telerik team
answered on 21 Jun 2016, 12:50 PM
Hi ,

Thank you for writing back.

The example discusses a scenario for populating items to drop-down list editor. The tricky part in this setup is to extract the newly entered value and update the  data source of the editor. To do so we need to perform a check if the element is already added and in that case call the base implementation.

I hope this helps. Please let me know if you need further assistance.

Regards,
Hristo Merdjanov
Telerik
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
GridView
Asked by
Morghabi
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Morghabi
Top achievements
Rank 1
Share this question
or