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

Select Row

Scheduled Pinned Locked Moved C#
helpcss
12 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 Rmokkenstorm

    I have a problem using a datagrid. I have 2 forms. 1 with a data grid and one textbox (for test use) and the second form has a couple of textboxes. now i use a CustomRowEventArgs to select the row. In form 1 this works.. I can even read The first collumn in the Textbox (for test use) I also let him open the second form. but there it does nothing. If needed I can past the code or pieces of the code here. I really need some help..

    A Offline
    A Offline
    AB7771
    wrote on last edited by
    #2

    Sorry, but i didn't get what are u trying to do? can u explain in detail and paste some code Regards, Pramod

    R 1 Reply Last reply
    0
    • A AB7771

      Sorry, but i didn't get what are u trying to do? can u explain in detail and paste some code Regards, Pramod

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

      The second form should be showing all the info that's clicked on the row of the datagrid on the first form . but in checkboxes. my code: it's looks kinna messy but i only post the important pieces here. Form 1 public delegate void CustomRowHandler(object sender, CustomRowEventArgs e); public static event CustomRowHandler CustomRow; InitializeComponent(); barryOracleDataAdapter1.Fill(barry11.Barry); CustomRow += new CustomRowHandler(customHandler_CustomRow); private void customHandler_CustomRow(object sender, WindowsApplication30.CustomRowEventArgs e) { Barry1 DSet = e.DSet; DataGrid grid = e.Grid; int row = e.Row; textBox2.Text = e.DSet.Tables[0].Rows[e.Row]["lastname"].ToString(); public void dataGrid_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { int rowIndex = dataGrid.CurrentRowIndex; if (CustomRow != null) { CustomRow(this, new CustomRowEventArgs(barry11,dataGrid, rowIndex)); DataForm1 frm = new DataForm1 (barry11,dataGrid, dataGrid.CurrentRowIndex); frm.Show(); } } public class CustomRowEventArgs : EventArgs { Barry1 barry11; DataGrid grid; int row; public CustomRowEventArgs(Barry1 DSet,DataGrid Grid,int Row) { barry11 = DSet; grid = Grid; row = Row; } public Barry1 DSet { get { return barry11; } } public DataGrid Grid { get { return grid; } } public int Row { get { return row; } } } --------------------------------------------------------------------------- Form 2 public DataForm1(Barry1 barry11, DataGrid dataGrid, int rowIndex) { // // Required for Windows Form Designer support // InitializeComponent(); Form1.CustomRow += new WindowsApplication30.CustomRowHandler(customHandler_CustomRow); private void customHandler_CustomRow(object sender, WindowsApplication30.CustomRowEventArgs e) { Barry1 DSet = e.DSet; DataGrid grid = e.Grid; int row = e.Row; editLASTNAME.Text = e.DSet.Tables[0].Rows[e.Row]["Firstname"].ToString(); }

      A 1 Reply Last reply
      0
      • R Rmokkenstorm

        The second form should be showing all the info that's clicked on the row of the datagrid on the first form . but in checkboxes. my code: it's looks kinna messy but i only post the important pieces here. Form 1 public delegate void CustomRowHandler(object sender, CustomRowEventArgs e); public static event CustomRowHandler CustomRow; InitializeComponent(); barryOracleDataAdapter1.Fill(barry11.Barry); CustomRow += new CustomRowHandler(customHandler_CustomRow); private void customHandler_CustomRow(object sender, WindowsApplication30.CustomRowEventArgs e) { Barry1 DSet = e.DSet; DataGrid grid = e.Grid; int row = e.Row; textBox2.Text = e.DSet.Tables[0].Rows[e.Row]["lastname"].ToString(); public void dataGrid_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { int rowIndex = dataGrid.CurrentRowIndex; if (CustomRow != null) { CustomRow(this, new CustomRowEventArgs(barry11,dataGrid, rowIndex)); DataForm1 frm = new DataForm1 (barry11,dataGrid, dataGrid.CurrentRowIndex); frm.Show(); } } public class CustomRowEventArgs : EventArgs { Barry1 barry11; DataGrid grid; int row; public CustomRowEventArgs(Barry1 DSet,DataGrid Grid,int Row) { barry11 = DSet; grid = Grid; row = Row; } public Barry1 DSet { get { return barry11; } } public DataGrid Grid { get { return grid; } } public int Row { get { return row; } } } --------------------------------------------------------------------------- Form 2 public DataForm1(Barry1 barry11, DataGrid dataGrid, int rowIndex) { // // Required for Windows Form Designer support // InitializeComponent(); Form1.CustomRow += new WindowsApplication30.CustomRowHandler(customHandler_CustomRow); private void customHandler_CustomRow(object sender, WindowsApplication30.CustomRowEventArgs e) { Barry1 DSet = e.DSet; DataGrid grid = e.Grid; int row = e.Row; editLASTNAME.Text = e.DSet.Tables[0].Rows[e.Row]["Firstname"].ToString(); }

        A Offline
        A Offline
        AB7771
        wrote on last edited by
        #4

        just change the following statement DataForm1 frm = new DataForm1 (barry11,dataGrid, dataGrid.CurrentRowIndex); with DataForm1 frm = new DataForm1 (barry11,dataGrid, rowIndex); Hope that solves ur problem Regards, Pramod

        R 1 Reply Last reply
        0
        • A AB7771

          just change the following statement DataForm1 frm = new DataForm1 (barry11,dataGrid, dataGrid.CurrentRowIndex); with DataForm1 frm = new DataForm1 (barry11,dataGrid, rowIndex); Hope that solves ur problem Regards, Pramod

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

          Too bad.. I've tried that but the problem remains.

          R 1 Reply Last reply
          0
          • R Rmokkenstorm

            Too bad.. I've tried that but the problem remains.

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

            does anyone else have some solution or information?

            E 1 Reply Last reply
            0
            • R Rmokkenstorm

              does anyone else have some solution or information?

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

              I suggest you skip the event handling i the second form. I really can't see the purpose of it. But, perhaps I get it wrong. Just assign the values to the textbox in the second form. You've got all the information you need through the constructor. Like this: public DataForm1(Barry1 barry11, DataGrid dataGrid, int rowIndex) { // // Required for Windows Form Designer support // InitializeComponent(); PopulateTextBoxes(barry11, dataGrid, rowIndex); private void PopulateTextBoxes(Barry1 barry11, DataGrid dataGrid, int rowIndex) { editLASTNAME.Text = barry11.Tables[0].Rows[rowIndex]["Firstname"].ToString(); }

              R 1 Reply Last reply
              0
              • E esjq

                I suggest you skip the event handling i the second form. I really can't see the purpose of it. But, perhaps I get it wrong. Just assign the values to the textbox in the second form. You've got all the information you need through the constructor. Like this: public DataForm1(Barry1 barry11, DataGrid dataGrid, int rowIndex) { // // Required for Windows Form Designer support // InitializeComponent(); PopulateTextBoxes(barry11, dataGrid, rowIndex); private void PopulateTextBoxes(Barry1 barry11, DataGrid dataGrid, int rowIndex) { editLASTNAME.Text = barry11.Tables[0].Rows[rowIndex]["Firstname"].ToString(); }

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

                Dude you really are great It works at once. I would like to thank you 1000 time but hope you agree with one big Thanks. Thank you so verry much you really are awesome.

                E 1 Reply Last reply
                0
                • R Rmokkenstorm

                  Dude you really are great It works at once. I would like to thank you 1000 time but hope you agree with one big Thanks. Thank you so verry much you really are awesome.

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

                  You're welcome! :-)

                  R 1 Reply Last reply
                  0
                  • E esjq

                    You're welcome! :-)

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

                    Oh just one thing:P now I have this datagrid and a detail form. now i adjust my button. i want a previos button on my second form.. code on form1: this is on my mouse up event of my datagrid ------------------------------------- DataForm1 tmpForm = new DataForm1 (barry11,dataGrid, rowIndex); tmpForm.Location = this.Location; tmpForm.Show(); this.Hide(); --------------------------------------------- DataForm1: private System.Windows.Forms.Form _previousForm; and then comes this.. thinks this is a really bad way to do it:P public DataForm1(Barry1 barry11, DataGrid dataGrid, int rowIndex) { InitializeComponent(); PopulateTextBoxes(barry11, dataGrid, rowIndex); } public DataForm1(System.Windows.Forms.Form tmpForm) { InitializeComponent(); _previousForm = tmpForm; } think this should be done other than this.. but i don't know how:( last peace of code private void btnbutton1_Click(object sender, System.EventArgs e) { // show previous _previousForm.Location = this.Location; _previousForm.Show(); // close this form this.Close(); }

                    E 1 Reply Last reply
                    0
                    • R Rmokkenstorm

                      Oh just one thing:P now I have this datagrid and a detail form. now i adjust my button. i want a previos button on my second form.. code on form1: this is on my mouse up event of my datagrid ------------------------------------- DataForm1 tmpForm = new DataForm1 (barry11,dataGrid, rowIndex); tmpForm.Location = this.Location; tmpForm.Show(); this.Hide(); --------------------------------------------- DataForm1: private System.Windows.Forms.Form _previousForm; and then comes this.. thinks this is a really bad way to do it:P public DataForm1(Barry1 barry11, DataGrid dataGrid, int rowIndex) { InitializeComponent(); PopulateTextBoxes(barry11, dataGrid, rowIndex); } public DataForm1(System.Windows.Forms.Form tmpForm) { InitializeComponent(); _previousForm = tmpForm; } think this should be done other than this.. but i don't know how:( last peace of code private void btnbutton1_Click(object sender, System.EventArgs e) { // show previous _previousForm.Location = this.Location; _previousForm.Show(); // close this form this.Close(); }

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

                      I really see no need to hide the first form. I would do like this instead... DataForm1 tmpForm = new DataForm1 (barry11,dataGrid, rowIndex); //tmpForm.Location = this.Location; tmpForm.ShowDialog(); //this.Hide(); ...and skip all the code to restore the first form in DataForm1.

                      R 1 Reply Last reply
                      0
                      • E esjq

                        I really see no need to hide the first form. I would do like this instead... DataForm1 tmpForm = new DataForm1 (barry11,dataGrid, rowIndex); //tmpForm.Location = this.Location; tmpForm.ShowDialog(); //this.Hide(); ...and skip all the code to restore the first form in DataForm1.

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

                        but i really want to hide the first form:P

                        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