0
if (e.RowIndex >= 0)
{
    //gets a collection that contains all the rows
    DataGridViewRow row = this.tbl_deliveryDataGridView.Rows[e.RowIndex];

    //populate the textbox from specific value of the coordinates of column and row. 
    noTextBox.Text = row.Cells[0].Value.ToString();
    supplierTextBox.Text = row.Cells[1].Value.ToString();
    invoiceNumberTextBox.Text = row.Cells[2].Value.ToString();
    dRNumberTextBox.Text = row.Cells[3].Value.ToString();
    pONumberTextBox.Text = row.Cells[4].Value.ToString();
}

Is it possible to change the numbers inside the bracket into column name? How?

  • 2
    possible duplicate of [Datagridviewrow using column name instead of index](http://stackoverflow.com/questions/13583687/datagridviewrow-using-column-name-instead-of-index) – nsgocev Aug 11 '14 at 06:45
  • 1
    `row.Cells["YourColumnName"]` – Sriram Sakthivel Aug 11 '14 at 06:47
  • @SriramSakthivel there's an error, here: "An unhandled exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll Additional information: Column named Supplier cannot be found." how come the column name cannot be found? i correct is thrice if the spelling is correct, and it is. how come? – user3875997 Aug 11 '14 at 06:55
  • You need to post more code to answer this question. How do you populate column? DataBound and auto generated columns? Or manually done? Show those code please – Sriram Sakthivel Aug 11 '14 at 06:57
  • 1
    @user3875997 are you sure that **Supplier** is a value of [**Name**](http://msdn.microsoft.com/ru-ru/library/system.windows.forms.datagridviewcolumn.name.aspx) property of your column? I assume that Supplier is a value of [**HeaderText**](http://msdn.microsoft.com/ru-ru/library/system.windows.forms.datagridviewcolumn.headertext.aspx) property. – Ivan Zub Aug 11 '14 at 07:07
  • @SriramSakthivel is that the connection string? – user3875997 Aug 11 '14 at 07:14
  • @IvanZub I see. Thanks! I thought, i will just follow what's name of the column. – user3875997 Aug 11 '14 at 07:21
  • May be you are getting the exception because you are missing the *.Value.ToString();* from Sriram's suggestion. So it should look like this: row.Cells["ColName1"].Value.ToString() – Pabinator Aug 12 '14 at 03:35

0 Answers0