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. C#: How to retrieve text from dgView cell and displayit in the button?

C#: How to retrieve text from dgView cell and displayit in the button?

Scheduled Pinned Locked Moved C#
questioncsharphelptutorial
9 Posts 5 Posters 1 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.
  • L Offline
    L Offline
    LAPEC
    wrote on last edited by
    #1

    Hello everyone I have posted a question yesterday but no one seems to answer my question. I thought that the Code Project Forum is there for people to help who dont have much knowledge on programming... Kind Regards Roni

    D E OriginalGriffO L 4 Replies Last reply
    0
    • L LAPEC

      Hello everyone I have posted a question yesterday but no one seems to answer my question. I thought that the Code Project Forum is there for people to help who dont have much knowledge on programming... Kind Regards Roni

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      First, this is a volunteer effort. The regulars who come here to answer questions do so on THEIR time, not yours. If you want answers to your questions on your schedule, call up Microsoft and pay for the support. What you just did with your post here is extremely rude.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      1 Reply Last reply
      0
      • L LAPEC

        Hello everyone I have posted a question yesterday but no one seems to answer my question. I thought that the Code Project Forum is there for people to help who dont have much knowledge on programming... Kind Regards Roni

        E Offline
        E Offline
        Enobong Adahada
        wrote on last edited by
        #3

        create an event for the gridview like so; private void dgv_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { //runs when the mouse is clicked over a cell if (e.RowIndex > -1 && e.ColumnIndex > -1) { if (e.Button == MouseButtons.Left) { //single-click left mouse button if (dgv.SelectionMode != DataGridViewSelectionMode.CellSelect) { dgv.SelectionMode = DataGridViewSelectionMode.CellSelect; int row = dgv.CurrentCell.RowIndex; int col = dgv.CurrentCell.ColumnIndex; } } textbox.text=dgv.Rows[row].Cells[col].Value.ToString(); } Remeber to Create the same event in the Form.Designer.cs file for the Datagridview. Hope this Helps

        L 1 Reply Last reply
        0
        • L LAPEC

          Hello everyone I have posted a question yesterday but no one seems to answer my question. I thought that the Code Project Forum is there for people to help who dont have much knowledge on programming... Kind Regards Roni

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          LAPEC wrote:

          no one seems to answer my question

          There could be a number of reasons for that: 1) No body knew the answer. 2) No body could be bothered to work out what the question was, because of the large lump of code they didn't want to bother with. 3) You didn't seem to have shown much effort in working on your problem yourself. 4) Some combination of the above. You have to remember: not everybody looks at Q&A; nobody here gets paid for this; most of us have jobs which do pay and expect a certain amount of work from us. You aren't helping yourself by taking a whining, petulant tone in your "bump" message...

          Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • L LAPEC

            Hello everyone I have posted a question yesterday but no one seems to answer my question. I thought that the Code Project Forum is there for people to help who dont have much knowledge on programming... Kind Regards Roni

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            LAPEC wrote:

            I thought that the Code Project Forum is there for people to help who dont have much knowledge on programming...

            It's a forum, people meet. Sometimes they help each other, but being a member is no replacement for an education.

            I are Troll :suss:

            1 Reply Last reply
            0
            • E Enobong Adahada

              create an event for the gridview like so; private void dgv_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { //runs when the mouse is clicked over a cell if (e.RowIndex > -1 && e.ColumnIndex > -1) { if (e.Button == MouseButtons.Left) { //single-click left mouse button if (dgv.SelectionMode != DataGridViewSelectionMode.CellSelect) { dgv.SelectionMode = DataGridViewSelectionMode.CellSelect; int row = dgv.CurrentCell.RowIndex; int col = dgv.CurrentCell.ColumnIndex; } } textbox.text=dgv.Rows[row].Cells[col].Value.ToString(); } Remeber to Create the same event in the Form.Designer.cs file for the Datagridview. Hope this Helps

              L Offline
              L Offline
              LAPEC
              wrote on last edited by
              #6

              Hi Enobong Adahada thanks for replying to my message, I have managed to work around my code refering to the question I posted yesterday but for some reason its not getting the cell value number to display it in the button. If you dont mind please you can have a look my question (under the View Unanswered Question) provided with sample of code and tell me if I missing something.... Thanks in advance kind regards roni

              E 1 Reply Last reply
              0
              • L LAPEC

                Hi Enobong Adahada thanks for replying to my message, I have managed to work around my code refering to the question I posted yesterday but for some reason its not getting the cell value number to display it in the button. If you dont mind please you can have a look my question (under the View Unanswered Question) provided with sample of code and tell me if I missing something.... Thanks in advance kind regards roni

                E Offline
                E Offline
                Enobong Adahada
                wrote on last edited by
                #7

                Can you post the code u are using so i can see if there are logic bugs.

                L 1 Reply Last reply
                0
                • E Enobong Adahada

                  Can you post the code u are using so i can see if there are logic bugs.

                  L Offline
                  L Offline
                  LAPEC
                  wrote on last edited by
                  #8

                  Here is the code... I have two forms on my project (Form1 & Form2). -In Form1 I have two Buttons (Starter & Main). Both these buttons on click event, they call database sql-query and genereate into form the records as Buttons. -In Form2 I have a Button (Starter) and DataGridView. Also this button on click event calls database sql-query and generates records in DatagridView. DataGridView has four columns: (Note: On columns [0] and [1] data are genereated from database, the columns [2] and [3] are template columns genereated at run-time also filled with data at run-time) Now in Form2 when I double_click inside the Cell under the Qty In Stock column, a dialog-box pops up and allows me to enter the number in to that particular cell. Lets say Row-1: like so...

                  FoodName FoodType Qty In Stock Status

                  Soup Starter 10 Allways On Stock

                  Based on this: How can I take the value of that cell = 10 and dispalyit on the bottom-right corner of the Button (in this case button Soup). This is what the Soup Button should look like (in Form1): (Note: The Button called Soup is generated from database...)

                  ##############

                  Soup

                  10

                  ##############

                  Here is the code of dataGridView1_CellClick event (in Form2)...

                  private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
                  {
                  if (e.ColumnIndex == 2)
                  {
                  // Value is given in case the cell is empty
                  string cellContent = "0";
                  if (this.dataGridView1[e.ColumnIndex, e.RowIndex].Value != null)
                  {
                  cellContent = this.dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
                  }

                              using (InputBox ib = new InputBox("Enter new stock amount:", this.dataGridView1\[0, e.RowIndex\].Value.ToString(), cellContent))
                              {
                                  if (ib.ShowDialog() == DialogResult.OK)
                                  {
                                      this.dataGridView1\[e.ColumnIndex, e.RowIndex\].Value = ib.Result;
                                      cellContent = ib.Result;
                                  }
                              }
                          }
                      }
                  

                  This is the code of InputBox dialog where it allows me to enter quantity in to the Cell of dataGridView1...

                  public partial class InputBox : Form
                  {
                  public InputBox(string tex

                  OriginalGriffO 1 Reply Last reply
                  0
                  • L LAPEC

                    Here is the code... I have two forms on my project (Form1 & Form2). -In Form1 I have two Buttons (Starter & Main). Both these buttons on click event, they call database sql-query and genereate into form the records as Buttons. -In Form2 I have a Button (Starter) and DataGridView. Also this button on click event calls database sql-query and generates records in DatagridView. DataGridView has four columns: (Note: On columns [0] and [1] data are genereated from database, the columns [2] and [3] are template columns genereated at run-time also filled with data at run-time) Now in Form2 when I double_click inside the Cell under the Qty In Stock column, a dialog-box pops up and allows me to enter the number in to that particular cell. Lets say Row-1: like so...

                    FoodName FoodType Qty In Stock Status

                    Soup Starter 10 Allways On Stock

                    Based on this: How can I take the value of that cell = 10 and dispalyit on the bottom-right corner of the Button (in this case button Soup). This is what the Soup Button should look like (in Form1): (Note: The Button called Soup is generated from database...)

                    ##############

                    Soup

                    10

                    ##############

                    Here is the code of dataGridView1_CellClick event (in Form2)...

                    private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
                    {
                    if (e.ColumnIndex == 2)
                    {
                    // Value is given in case the cell is empty
                    string cellContent = "0";
                    if (this.dataGridView1[e.ColumnIndex, e.RowIndex].Value != null)
                    {
                    cellContent = this.dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
                    }

                                using (InputBox ib = new InputBox("Enter new stock amount:", this.dataGridView1\[0, e.RowIndex\].Value.ToString(), cellContent))
                                {
                                    if (ib.ShowDialog() == DialogResult.OK)
                                    {
                                        this.dataGridView1\[e.ColumnIndex, e.RowIndex\].Value = ib.Result;
                                        cellContent = ib.Result;
                                    }
                                }
                            }
                        }
                    

                    This is the code of InputBox dialog where it allows me to enter quantity in to the Cell of dataGridView1...

                    public partial class InputBox : Form
                    {
                    public InputBox(string tex

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #9

                    Reason for my vote of 1: Why cut and paste that lot? Why did you not just give a link to your Q&A question? Now, you have two places with the same info, that potentially could duplicate work if anyone does answer. :doh:

                    Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    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