1 Replies - 3063 Views - Last Post: 02 November 2012 - 08:15 AM Rate Topic: -----

#1 mohsin1122  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-November 12

how to load the data from datagridview into windows forms accordingly

Posted 02 November 2012 - 06:11 AM

i want that when i click on any record the date of that record will be loaded in forms above
help me please

i am using CellMouseClick event but in the form it show System.Windows.Forms.DataGridViewSelectedRowCollection instead of showing data

i am using this function

private void Customers_view_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
          {
            ContactLastName.Text = Customers_view.SelectedRows.ToString();
          }



Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: how to load the data from datagridview into windows forms accordingly

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3579
  • View blog
  • Posts: 11,132
  • Joined: 05-May 12

Re: how to load the data from datagridview into windows forms accordingly

Posted 02 November 2012 - 08:15 AM

That is because on line 3 you are converting the SelectedRows property to a string. You need to indicate which row among the selected rows, and which column in that row you want to convert to a string to put into your textbox.

Something like:
DataGridViewRow row = Customers_view.SelectedRows[0];   // pick first selected row
DataGridViewCell cell = row.Cells['Date'];              // pick up the cell in the 'Date' column
yourTextBox.Text = cell.FormattedValue.ToString();      // pick the formatted value


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1