DataGridViewColumn, DataGridViewTextBoxCell에서 파생시키고 IDataGridViewEditingControl을 구현하는 datagridview에 대한 사용자 지정 열을 만들었습니다.DataGridView에서 이상한 문자 'q'문제 Custom DataGridViewColumn 셀
간단한 TextBox를 포함하는 사용자 정의 컨트롤을 만들고이 컨트롤을 해당 컨트롤의 편집 컨트롤로 사용했습니다.
이제이 시나리오에 이상한 문제가 발생합니다. 문자 'q'를 누르면 DataGridView의 사용자 지정 열에있는 셀에 아무 것도 표시되지 않지만 다른 키를 누르면 해당 셀에 제대로 표시됩니다.
여기에 어떤 문제가있을 수 있습니까? 나는 모든 이벤트를 디버깅하여 모든 종류의 방법을 시도했지만 아무 것도 찾을 수 없었다.
내가 작성한 사용자 정의 열의 아래 코드를 제공하고 있습니다. 나는 디자이너와 DataGridView를 통해 내 DataGridView에있는 열 중 하나로이 추가 한
public class CustomControlColumn : DataGridViewColumn
{
public CustomControlColumn() : base(new CustomTextCell()) { }
public override DataGridViewCell CellTemplate
{
get
{
return base.CellTemplate;
}
set
{
// Ensure that the cell used for the template is a CustomComboCell.
if (value != null && !value.GetType().IsAssignableFrom(typeof(CustomTextCell)))
{
throw new InvalidCastException("Must be a CustomTextCell");
}
base.CellTemplate = value;
}
}
}
public class CustomTextCell : DataGridViewTextBoxCell
{
public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
// Set the value of the editing control to the current cell value.
base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
var control = DataGridView.EditingControl as CustomTextBoxControl;
if (OwningColumn == null)
return;
// Use the default row value when Value property is null.
if (Value == null)
{
control.Text = string.Empty;
}
else
{
control.Text = Value.ToString();
}
}
public override Type EditType
{
get
{
// Return the type of the editing contol that CustomComboCell uses.
return typeof(CustomControlEditingControl);
}
}
public override Type ValueType
{
get
{
// Return the type of the value that CustomTextCell contains.
return typeof(String);
}
}
public override object DefaultNewRowValue
{
get
{
// Use the empty string as the default value.
return string.Empty;
}
}
}
class CustomControlEditingControl : CustomTextBoxControl, IDataGridViewEditingControl
{
public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
// Nothing to do
}
public bool EditingControlWantsInputKey(Keys keyData, bool dataGridViewWantsInputKey)
{
// Let the control handle the keys listed.
switch (keyData & Keys.KeyCode)
{
case Keys.Left:
case Keys.Up:
case Keys.Down:
case Keys.Right:
case Keys.Home:
case Keys.End:
case Keys.PageDown:
case Keys.PageUp:
return true;
default:
return false;
}
}
public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
{
return EditingControlFormattedValue;
}
public DataGridView EditingControlDataGridView { get; set; }
public object EditingControlFormattedValue
{
get { return Text; }
set { Text = value.ToString(); }
}
public int EditingControlRowIndex { get; set;}
public bool EditingControlValueChanged { get; set; }
public Cursor EditingPanelCursor
{
get { return base.Cursor; }
}
public bool RepositionEditingControlOnValueChange
{
get { return false; }
}
}
는 어떤 데이터 소스와 연결되어 있지 않습니다.
아무도이 코드에서 문제를 지적 할 수 있습니까?
은 "q는"이제까지 상자에 표시 않습니다 ... 나? – curtisk
@curtisk : 어딘가에서 복사하고 붙여 넣으면 표시되지 않습니다. 또한 Shift + q를 누르면 대문자 'Q'로 표시됩니다. 나는이 행동에 대해 대단히 놀랐다. – JPReddy
'q'키가 아닙니다. 화살표 키를 사용하여 셀을 탐색하고 키를 누르면 해당 키 입력이 무시됩니다. 그렇지 않으면 그것은 잘 작동합니다. 'q'및 기타 키 입력이 필요합니다. –