【发布时间】:2014-05-05 08:30:21
【问题描述】:
我想知道如何设置 gridviewcomboboxcolumn 的选定元素。
作为一个前言:我正在使用具有自动完成模式的列,以便 具有自动完成功能,但我也想向列表中添加新元素。 到目前为止,它工作顺利,除了一种情况:
我已经有了:
T1
T12
T123
在数据源中。
然后当我选择了例如 T12 并执行退格键来选择 T1 我遇到了需要手动单击列表中的 T1 的问题,因为没有选择 T1,因为显示了多种可能性。因此,当我离开编辑器模式而不手动选择 T1 时,我将 T12 作为选定项目。
我想改变这种行为,使第一个找到的项目被预先选择(总是)。 (不管是新元素还是改成元素可以这么说)
目前我已经为 cellendedit 添加了一个自定义处理程序,以将新值添加到列表中:
private void MainFormGridView_CellEndEdit(object Sender, GridViewCellEventArgs eventArgs)
{
var virtualizedCurrentCell = ((Telerik.WinControls.UI.GridVirtualizedCellElement)(currentCell));
var currentGridviewComboBoxColumn = ((Telerik.WinControls.UI.GridViewComboBoxColumn)(virtualizedCurrentCell.Data));
if (((List<string>)currentGridviewComboBoxColumn.DataSource).IndexOf((string)currentCell.Value) > -1)
{
foundValueInList = true;
}
if (!foundValueInList)
{
((List<string>)currentGridviewComboBoxColumn.DataSource).Add((string)currentCell.Value);
}
}
列本身就是以这种方式创建的(在添加到 gridview 之前,它是其中的一部分:
GridViewComboBoxColumn newColumn;
newColumn = new GridViewComboBoxColumn();
((GridViewComboBoxColumn)newColumn).DataSource = (from c in entity.myOffer
orderby c.customer
where c.customer!= null
select c.customer)
.Distinct()
.ToList();
((GridViewComboBoxColumn)newColumn).DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown;
((GridViewComboBoxColumn)newColumn).AutoCompleteMode = AutoCompleteMode.SuggestAppend;
newColumn.FieldName = "customer";
newColumn.Name = "customer";
newColumn.HeaderText = "Customer";
newColumn.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
newColumn.Width = 100;
listOfColumns.Add(newColumn);
this.MainFormGridView.Columns.Add(newColumn);
所以问题是我可以做些什么来选择下拉列表中的特定项目,并且 CellEndEdit 是正确的位置(我怀疑)?
【问题讨论】:
标签: c# winforms autocomplete telerik datagridviewcombobox