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
;