Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem editing DataGrid

Problem editing DataGrid

Scheduled Pinned Locked Moved C#
helpcomdesignquestionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maxdd 7
    wrote on last edited by
    #1

    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 ?

    D 1 Reply Last reply
    0
    • M Maxdd 7

      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 ?

      D Offline
      D Offline
      Dr Walt Fair PE
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups