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. select row in Datagridview C#

select row in Datagridview C#

Scheduled Pinned Locked Moved C#
csharphelpannouncement
6 Posts 3 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.
  • C Offline
    C Offline
    csanda1
    wrote on last edited by
    #1

    Hi all Im using C# 2005, I have a button search which when you click refreshes the datagridview and displays the search results that's fine. Now what I want is when I select a row or cell the data in that row appear on the respective textboxes in the form to allow the user to update if they want, is there a way that I can do this or another way maybe. Any help will be appreciated!! private void btnSearch_Click(object sender, EventArgs e) { string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; string Company = txtSearch.Text ; string select = "SELECT * FROM ecmain WHERE CompanyName Like '" + Company + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); datatryConn.Open(); OleDbDataAdapter da = new OleDbDataAdapter(select, datatryConn); DataSet ds = new DataSet(); da.Fill(ds, "ecmain"); dataGridView.AutoGenerateColumns = true; dataGridView.DataSource = ds; dataGridView.DataMember = "ecmain"; datatryConn.Close(); Thanx in advance Csanda

    R 1 Reply Last reply
    0
    • C csanda1

      Hi all Im using C# 2005, I have a button search which when you click refreshes the datagridview and displays the search results that's fine. Now what I want is when I select a row or cell the data in that row appear on the respective textboxes in the form to allow the user to update if they want, is there a way that I can do this or another way maybe. Any help will be appreciated!! private void btnSearch_Click(object sender, EventArgs e) { string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; string Company = txtSearch.Text ; string select = "SELECT * FROM ecmain WHERE CompanyName Like '" + Company + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); datatryConn.Open(); OleDbDataAdapter da = new OleDbDataAdapter(select, datatryConn); DataSet ds = new DataSet(); da.Fill(ds, "ecmain"); dataGridView.AutoGenerateColumns = true; dataGridView.DataSource = ds; dataGridView.DataMember = "ecmain"; datatryConn.Close(); Thanx in advance Csanda

      R Offline
      R Offline
      Rocky
      wrote on last edited by
      #2

      well I'm out of touch from desktop applicatoins for quite sometime now but if u want to show the data of a cell of a dgv in a textbox then u need to use an event , its called onCellClick I think. use its DatagridvieweventArgs object that will give the RowIndex and ColumnIndex Properties to get the data of that particular cell. I'm sorry I cant give u the code coz I'm bussy in another project at the moment Hope it helps

      Rocky You can't climb up a ladder with your hands in your pockets.

      C 1 Reply Last reply
      0
      • R Rocky

        well I'm out of touch from desktop applicatoins for quite sometime now but if u want to show the data of a cell of a dgv in a textbox then u need to use an event , its called onCellClick I think. use its DatagridvieweventArgs object that will give the RowIndex and ColumnIndex Properties to get the data of that particular cell. I'm sorry I cant give u the code coz I'm bussy in another project at the moment Hope it helps

        Rocky You can't climb up a ladder with your hands in your pockets.

        C Offline
        C Offline
        csanda1
        wrote on last edited by
        #3

        I tried that one but it doesnt recognise RowIndex and ColumnIndex properties.

        R A 2 Replies Last reply
        0
        • C csanda1

          I tried that one but it doesnt recognise RowIndex and ColumnIndex properties.

          R Offline
          R Offline
          Rocky
          wrote on last edited by
          #4

          what do u mean it doesnt recognize rowindex and columnindex. show me the code plz

          Rocky You can't climb up a ladder with your hands in your pockets.

          C 1 Reply Last reply
          0
          • C csanda1

            I tried that one but it doesnt recognise RowIndex and ColumnIndex properties.

            A Offline
            A Offline
            Andrei Ungureanu
            wrote on last edited by
            #5

            You can use gridview.CurrentCell.RowIndex or from the event args of the CellClick event e.RowIndex. Hope it helps.

            I will use Google before asking dumb questions

            1 Reply Last reply
            0
            • R Rocky

              what do u mean it doesnt recognize rowindex and columnindex. show me the code plz

              Rocky You can't climb up a ladder with your hands in your pockets.

              C Offline
              C Offline
              csanda1
              wrote on last edited by
              #6

              Heres the code below. dataGridView.CurrentCell.Selected = false; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true; dataGridView.CurrentCell = dataGridView.SelectedCells[0];

              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