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. Datagrid select row

Datagrid select row

Scheduled Pinned Locked Moved C#
csharpdatabasewinformshelpquestion
4 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.
  • R Offline
    R Offline
    Rmokkenstorm
    wrote on last edited by
    #1

    Hi there can someone please help me? I want to select a row from form1 and then open another form (form2) which shows the same row but with some more fields... so.. form 1. datagrid about 4 collums from the database table. then dubbel click on it form 2. a couple of textfields.. (about 10) which shows all the records in the row. i use C# winforms. i've tried a lot of thinks but it just won't work....

    C 1 Reply Last reply
    0
    • R Rmokkenstorm

      Hi there can someone please help me? I want to select a row from form1 and then open another form (form2) which shows the same row but with some more fields... so.. form 1. datagrid about 4 collums from the database table. then dubbel click on it form 2. a couple of textfields.. (about 10) which shows all the records in the row. i use C# winforms. i've tried a lot of thinks but it just won't work....

      C Offline
      C Offline
      CWIZO
      wrote on last edited by
      #2

      Moddify the constructor of form2 so that it takes the ID of the row and then display the information you need. On form1 make a event hanlder that will respond to the doubleclick on the datagrid and then make a new form in that event handler that will pass the id of the row to the form2. Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

      R E 2 Replies Last reply
      0
      • C CWIZO

        Moddify the constructor of form2 so that it takes the ID of the row and then display the information you need. On form1 make a event hanlder that will respond to the doubleclick on the datagrid and then make a new form in that event handler that will pass the id of the row to the form2. Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

        R Offline
        R Offline
        Rmokkenstorm
        wrote on last edited by
        #3

        but how? i actualy got al the coding.. but it just don't work.. and i really dont know why. public void dataGrid_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { int rowIndex = dataGrid1.CurrentRowIndex; if (CustomRow != null) { CustomRow(this, new CustomRowEventArgs(barry11,dataGrid1,rowIndex)); } } public class CustomRowEventArgs : EventArgs { public Barry1 DaSet; DataGrid grid; int row; public CustomRowEventArgs(Barry1 DSet,DataGrid Grid,int Row) { DaSet = DSet; grid = Grid; row = Row; } public Barry1 DSet { get { return DaSet; } } public DataGrid Grid { get { return grid; } } public int Row { get { return row; } } that DaSet.. should be barry11 (my dataset) DaSet was kinne like a test or something.. or what variable or class or something should i put there.. public virtual void customHandler_CustomRow(object sender, CustomRowEventArgs e) { Barry1 DaSet = e.DaSet; DataGrid dataGrid1 = e.Grid; int row = e.Row; textBox.Text = dataGrid1[e.Row,0].ToString(); this textbox stands on the same form so i could test it and see it quick if it works or not.. but it doesn't...

        1 Reply Last reply
        0
        • C CWIZO

          Moddify the constructor of form2 so that it takes the ID of the row and then display the information you need. On form1 make a event hanlder that will respond to the doubleclick on the datagrid and then make a new form in that event handler that will pass the id of the row to the form2. Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

          E Offline
          E Offline
          esjq
          wrote on last edited by
          #4

          Quick'n dirty... In the main form, when a row in the datagrid is double clicked: private void dgInfo_DoubleClick(object sender, System.EventArgs e) { Form2 frm=new Form2(ds, dgInfo.CurrentRowIndex); frm.ShowDialog(); } In the constructor of Form2: public Form2(DataSet ds, int index):this() { textBox1.Text=ds.Tables[0].Rows[index][0].ToString(); textBox2.Text=ds.Tables[0].Rows[index][1].ToString(); textBox3.Text=ds.Tables[0].Rows[index][2].ToString(); } Helpful perhaps...

          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