Problem editing DataGrid
-
I'm trying something similar to this: http://msdn.microsoft.com/en-us/library/ms838165.aspx[^] I used that code to handle de editing:
private void grdOrders_CurrentCellChanged(object sender,
System.EventArgs e)
{
if (!inUpdateMode)
{
if (inEditMode && !grdOrders.CurrentCell.Equals(editCell))
{
// Update edited cell
inUpdateMode = true;
grdOrders.Visible = false;
DataGridCell currentCell = grdOrders.CurrentCell;
grdOrders[editCell.RowNumber, editCell.ColumnNumber] =
txtEdit.Text;
grdOrders.CurrentCell = currentCell;
grdOrders.Visible = true;
inUpdateMode = false;
txtEdit.Visible = false;
inEditMode = false;
}// Enter edit mode editCell = grdOrders.CurrentCell; txtEdit.Text = (string)grdOrders\[editCell.RowNumber, editCell.ColumnNumber\]; Rectangle cellPos = grdOrders.GetCellBounds(editCell.RowNumber, editCell.ColumnNumber); txtEdit.Left = cellPos.Left - 1; txtEdit.Top = cellPos.Top + grdOrders.Top - 1; txtEdit.Width = cellPos.Width + 2; txtEdit.Height = cellPos.Height + 2; txtEdit.Visible = true; inEditMode = true;
}
}But I'm having a problem. I dont know what to put on Form1 Design so I'm getting the error: txtEdit does not exist on current context. Can you please help me ?
-
I'm trying something similar to this: http://msdn.microsoft.com/en-us/library/ms838165.aspx[^] I used that code to handle de editing:
private void grdOrders_CurrentCellChanged(object sender,
System.EventArgs e)
{
if (!inUpdateMode)
{
if (inEditMode && !grdOrders.CurrentCell.Equals(editCell))
{
// Update edited cell
inUpdateMode = true;
grdOrders.Visible = false;
DataGridCell currentCell = grdOrders.CurrentCell;
grdOrders[editCell.RowNumber, editCell.ColumnNumber] =
txtEdit.Text;
grdOrders.CurrentCell = currentCell;
grdOrders.Visible = true;
inUpdateMode = false;
txtEdit.Visible = false;
inEditMode = false;
}// Enter edit mode editCell = grdOrders.CurrentCell; txtEdit.Text = (string)grdOrders\[editCell.RowNumber, editCell.ColumnNumber\]; Rectangle cellPos = grdOrders.GetCellBounds(editCell.RowNumber, editCell.ColumnNumber); txtEdit.Left = cellPos.Left - 1; txtEdit.Top = cellPos.Top + grdOrders.Top - 1; txtEdit.Width = cellPos.Width + 2; txtEdit.Height = cellPos.Height + 2; txtEdit.Visible = true; inEditMode = true;
}
}But I'm having a problem. I dont know what to put on Form1 Design so I'm getting the error: txtEdit does not exist on current context. Can you please help me ?
From the page you referenced:
When a cell is tapped (both inEditMode and inUpdate mode is false), the current cell is saved (editCell). Then, the hidden TextBox (txtEdit) gets the current cell contents, is repositioned to the location of the current cell, and is made visible (over the current cell). When editing is complete and another cell is selected, the event code is disabled (inUpdateMode set to true) and the new cell is saved (currentCell) while the edited cell gets updated from the TextBox control. During the update the grid is not updated (Visible set to false), and when the update is complete the TextBox is hidden again.
If you want to do things the way they did, you need to create the hidden TextBox control named txtEdit on your form.
CQ de W5ALT
Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software