[Mono-bugs] [Bug 457307] New: DataGridView binding: Entered character is ignored
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Mon Dec 8 12:24:02 EST 2008
https://bugzilla.novell.com/show_bug.cgi?id=457307
Summary: DataGridView binding: Entered character is ignored
Product: Mono: Class Libraries
Version: SVN
Platform: x86
OS/Version: Windows Vista
Status: NEW
Severity: Normal
Priority: P5 - None
Component: Windows.Forms
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: kobruleht2 at hot.ee
QAContact: mono-bugs at lists.ximian.com
Found By: ---
To reproduce, run code, press a
Observed: a is ignored
Expected: a must appear in combobox
using System;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using System.Collections.Generic;
using System.ComponentModel;
public static class AppMainEntry
{
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
var f = new Form();
var grid = new DataGridView();
grid.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
ComboBoxColumn comboBoxColumn = new ComboBoxColumn();
ComboBoxCell comboBoxCell = new ComboBoxCell();
comboBoxColumn.CellTemplate = comboBoxCell;
comboBoxColumn.DisplayMember = "DisplayMember";
comboBoxColumn.ValueMember = "ValueMember";
comboBoxColumn.DataSource = new BindingList<XPickListEntity>();
var column = comboBoxColumn;
column.DataPropertyName = "Toode";
column.SortMode = DataGridViewColumnSortMode.Programmatic;
grid.Columns.Add(column);
var tr = new List<RidYY>();
var rids = new BindingList<RidYY>();
var bs = new BindingSource();
bs.DataSource = rids;
grid.DataSource = bs;
if (grid.CurrentCell != null)
grid.CurrentCell.Selected = false;
f.Controls.Add(grid);
f.Show();
grid.Focus();
Application.Run(f);
}
}
class RidYY
{
public string Toode { get; set; }
}
public class ComboBoxColumn : DataGridViewComboBoxColumn
{
public ComboBoxColumn()
: base()
{
}
public override DataGridViewCell CellTemplate
{
get
{
return base.CellTemplate;
}
set
{
if (value != null &&
!value.GetType().IsAssignableFrom(typeof(ComboBoxCell)))
{
string s = "Cell entity is not based upon the ComboBoxCell.";
throw new InvalidCastException(s);
}
base.CellTemplate = value;
}
}
public override object Clone()
{
ComboBoxColumn comboBoxColumn = (ComboBoxColumn)base.Clone();
return comboBoxColumn;
}
}
class ComboBoxCell : DataGridViewComboBoxCell
{
public ComboBoxCell()
: base()
{
FlatStyle = FlatStyle.Flat;
DisplayStyleForCurrentCellOnly = true;
//AutoComplete = true;
}
public override void InitializeEditingControl(int rowIndex, object
initialFormattedValue,
DataGridViewCellStyle dataGridViewCellStyle)
{
// TODO: if this is removed, sorting document rows without setting
focus to cell cauases error:
if (RowIndex == -1)
return;
ComboBoxColumn cbc = (ComboBoxColumn)OwningColumn;
ComboBoxEditingControl comboBoxEditingControl =
(ComboBoxEditingControl)DataGridView.EditingControl;
base.InitializeEditingControl(rowIndex, initialFormattedValue,
dataGridViewCellStyle);
comboBoxEditingControl.DropDownStyle = ComboBoxStyle.DropDown;
comboBoxEditingControl.AutoCompleteMode = AutoCompleteMode.None;
if (rowIndex > -1)
comboBoxEditingControl.Text = Value as string;
else
comboBoxEditingControl.Text = null;
}
public override Type EditType
{
get
{
return typeof(ComboBoxEditingControl);
}
}
}
internal class ComboBoxEditingControl : ComboBox, IDataGridViewEditingControl
{
protected int rowIndex;
internal DataGridView dataGridView;
protected bool valueChanged;
public ComboBoxEditingControl() : base() { }
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
NotifyDataGridViewOfValueChange();
}
protected virtual void NotifyDataGridViewOfValueChange()
{
valueChanged = true;
if (dataGridView != null)
{
dataGridView.NotifyCurrentCellDirty(true);
}
}
#region IDataGridViewEditingControl Members
Cursor IDataGridViewEditingControl.EditingPanelCursor
{
get
{
return Cursors.IBeam;
}
}
DataGridView IDataGridViewEditingControl.EditingControlDataGridView
{
get
{
return dataGridView;
}
set
{
dataGridView = value;
}
}
object IDataGridViewEditingControl.EditingControlFormattedValue
{
set
{
if (value.ToString().Trim() != Text.Trim())
{
Text = value.ToString().Trim();
NotifyDataGridViewOfValueChange();
}
}
get
{
return Text.Trim();
}
}
object
IDataGridViewEditingControl.GetEditingControlFormattedValue(DataGridViewDataErrorContexts
context)
{
return Text;
}
bool IDataGridViewEditingControl.EditingControlWantsInputKey(
Keys keyData, bool dataGridViewWantsInputKey)
{
return !dataGridViewWantsInputKey;
}
void
IDataGridViewEditingControl.ApplyCellStyleToEditingControl(DataGridViewCellStyle
dataGridViewCellStyle)
{
}
void IDataGridViewEditingControl.PrepareEditingControlForEdit(bool
selectAll)
{
if (dataGridView.CurrentCell.Value == null)
{
return;
}
string code = dataGridView.CurrentCell.Value.ToString();
if (code.TrimEnd().Length == 0)
{
return;
}
ComboBoxCell ComboBoxCell = dataGridView.CurrentCell as ComboBoxCell;
string cellText = ComboBoxCell.FormattedValue.ToString();
if (cellText.TrimEnd().Length == 0)
{
return;
}
int pos = FindString(cellText);
if (pos < 0)
return;
SelectedIndex = pos;
Text = cellText;
if (selectAll)
{
SelectAll();
}
else
{
SelectionStart = Text.TrimEnd().Length;
}
}
bool IDataGridViewEditingControl.RepositionEditingControlOnValueChange
{
get
{
return false;
}
}
int IDataGridViewEditingControl.EditingControlRowIndex
{
get
{
return rowIndex;
}
set
{
this.rowIndex = value;
}
}
public bool EditingControlValueChanged
{
get
{
return valueChanged;
}
set
{
valueChanged = value;
}
}
#endregion
}
class XPickListEntity
{
public string DisplayMember { get; set; }
public object ValueMember { get; set; }
}
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list