所以我尝试将可编辑列添加到datagrid。我在http://msdn.microsoft.com/en-us/library/ms838165.aspx跟踪msdn示例 当我试图在文本框中输入数据时,这有点可行,这有点无视整点。我试图将focus()属性设置为文本框,但没有结果。 我正在使用紧凑的框架3.5。
如果有人愿意尝试,可以在这里找到150行代码 - http://pastebin.com/08bz8scH
你能说出我做错了什么吗?以下是重要的代码示例: private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
{
if (!inUpdateMode)
{
if (inEditMode && !dataGrid1.CurrentCell.Equals(editCell))
{
// Update edited cell
inUpdateMode = true;
dataGrid1.Visible = false;
DataGridCell currentCell = dataGrid1.CurrentCell;
dataGrid1[editCell.RowNumber, editCell.ColumnNumber] =
txtEdit.Text;
dataGrid1.CurrentCell = currentCell;
dataGrid1.Visible = true;
inUpdateMode = false;
txtEdit.Visible = false;
inEditMode = false;
bool ff = dataGrid1.TableStyles.IsReadOnly;
}
// Enter edit mode
editCell = dataGrid1.CurrentCell;
txtEdit.Text = ""; //(string)dataGrid1[editCell.RowNumber,editCell.ColumnNumber];
System.Drawing.Rectangle cellPos = dataGrid1.GetCellBounds(editCell.RowNumber,
editCell.ColumnNumber);
txtEdit.Left = cellPos.Left ;
txtEdit.Top = cellPos.Top + dataGrid1.Top ;
txtEdit.Width = cellPos.Width ;
txtEdit.Height = cellPos.Height ;
txtEdit.Visible = true;
txtEdit.Focus();
inEditMode = true;
}
}