How do I input data into specific cells in a datagrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • emiko771
    New Member
    • Mar 2012
    • 1

    How do I input data into specific cells in a datagrid

    I am new to C# and am not experienced in creating complex methods. I need to create a class that will input data into a DataGrid with set number of columns but an unknown number of rows. This method would need to use either SetText or TypeKeys in the designated cells.
    column examples:
    column 1: Phase ID
    column 2: Cost Code ID
    column 3: Number of Units
    column 4: Expenses
    column 5: Revenues

    I know that when I try to declare the cells, it is (column:row). The problem is I am unsure how to populate specific cells (for example: Phase ID, Expenses and Revenue only) with data that is passed into the method. Also the Phase ID and Cost Code ID have a PushButton for a drop list. The DataGrid class doesn't seem to have this functionality. Please help!
  • RhysW
    New Member
    • Mar 2012
    • 70

    #2
    Code:
    grd_datagrid.Rows[1].Cells[0].Value = "xyz";
    the 1 in the rows[1] means it will select the second row (the first row is rows[0]) the cells[0] means it iwll select the very first cell, the .value allows you change the vlaue of this cell to whatever is in the quotes

    you had a long wait for this but thats essentially how you do it! this relies on you knowing what row and cell you want things to go into, there are more complex ways of doing this when you dont know what row or cell you want to put data in but it is doable

    Comment

    • Mistica009
      New Member
      • Apr 2012
      • 1

      #3
      para hacer eso lo mas comodo es usar el evento "RowDataBou nd" del datagrid o gridview, donde tienes disponible lo siguiente:

      Code:
      if (e.Row.RowType == DataControlRowType.DataRow)
                  {
      DataRowView dataItem = (DataRowView)e.Row.DataItem;
      e.Row.Cells[0].Text = "Nuevo valor";
      
      }

      Comment

      Working...