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. The Lounge
  3. How can I pass data to DataGridView from another form?

How can I pass data to DataGridView from another form?

Scheduled Pinned Locked Moved The Lounge
helpquestioncssdatabasewinforms
5 Posts 5 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.
  • N Offline
    N Offline
    naouf10
    wrote on last edited by
    #1

    I just want to pass data to DataGridView from another form? I have 2 windows forms: - from1 contains DataGridView1 and button_frm1.The DataGridView have 3 columns and already have some data (6 rows) and DataGridView1 modifiers = Public. - form2 contains textBox1 and button_frm2. Now, when I click button_frm1 form2 appears and next when I click button_frm2 the value in the textBox should be inserted into DataGridView1 in column0 in the selected row. but instead, I got this error: "Index was out of range. Must be non-negative and less than the size of the collection". Please help me how to insert the textBox value from form2 into DataGridView1 in form1. What steps to follow? Thank you very much in advance. Here is the code I tried: Form1: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button_frm1_Click(object sender, EventArgs e) { Form2 frm2 = new Form2(); frm2.Show(); } } Form2: public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button_frm2(object sender, EventArgs e) { Form1 frm1 = new Form1(); textBox1.Text= frm1.dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); } }

    OriginalGriffO M R R 4 Replies Last reply
    0
    • N naouf10

      I just want to pass data to DataGridView from another form? I have 2 windows forms: - from1 contains DataGridView1 and button_frm1.The DataGridView have 3 columns and already have some data (6 rows) and DataGridView1 modifiers = Public. - form2 contains textBox1 and button_frm2. Now, when I click button_frm1 form2 appears and next when I click button_frm2 the value in the textBox should be inserted into DataGridView1 in column0 in the selected row. but instead, I got this error: "Index was out of range. Must be non-negative and less than the size of the collection". Please help me how to insert the textBox value from form2 into DataGridView1 in form1. What steps to follow? Thank you very much in advance. Here is the code I tried: Form1: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button_frm1_Click(object sender, EventArgs e) { Form2 frm2 = new Form2(); frm2.Show(); } } Form2: public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button_frm2(object sender, EventArgs e) { Form1 frm1 = new Form1(); textBox1.Text= frm1.dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); } }

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

      Start by looking around at what you are doing: see the bit at the top of teh page? Where it says "Technical discussions are encouraged, but click here to ask your programming question."? Perhaps if you paid attention you wouldn't annoy people, and you might get a better response. Then click on the red bit, and it'll take you here: http://www.codeproject.com/Questions/ask.aspx[^]

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

      "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
      • N naouf10

        I just want to pass data to DataGridView from another form? I have 2 windows forms: - from1 contains DataGridView1 and button_frm1.The DataGridView have 3 columns and already have some data (6 rows) and DataGridView1 modifiers = Public. - form2 contains textBox1 and button_frm2. Now, when I click button_frm1 form2 appears and next when I click button_frm2 the value in the textBox should be inserted into DataGridView1 in column0 in the selected row. but instead, I got this error: "Index was out of range. Must be non-negative and less than the size of the collection". Please help me how to insert the textBox value from form2 into DataGridView1 in form1. What steps to follow? Thank you very much in advance. Here is the code I tried: Form1: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button_frm1_Click(object sender, EventArgs e) { Form2 frm2 = new Form2(); frm2.Show(); } } Form2: public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button_frm2(object sender, EventArgs e) { Form1 frm1 = new Form1(); textBox1.Text= frm1.dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); } }

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        Well, you failed to pass the test[^]... Max.

        I'd rather be phishing!

        1 Reply Last reply
        0
        • N naouf10

          I just want to pass data to DataGridView from another form? I have 2 windows forms: - from1 contains DataGridView1 and button_frm1.The DataGridView have 3 columns and already have some data (6 rows) and DataGridView1 modifiers = Public. - form2 contains textBox1 and button_frm2. Now, when I click button_frm1 form2 appears and next when I click button_frm2 the value in the textBox should be inserted into DataGridView1 in column0 in the selected row. but instead, I got this error: "Index was out of range. Must be non-negative and less than the size of the collection". Please help me how to insert the textBox value from form2 into DataGridView1 in form1. What steps to follow? Thank you very much in advance. Here is the code I tried: Form1: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button_frm1_Click(object sender, EventArgs e) { Form2 frm2 = new Form2(); frm2.Show(); } } Form2: public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button_frm2(object sender, EventArgs e) { Form1 frm1 = new Form1(); textBox1.Text= frm1.dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); } }

          R Offline
          R Offline
          R Giskard Reventlov
          wrote on last edited by
          #4

          Delete your post and move it to the proper forum for asking coding questions. This is not a good start to your CP career! :thumbsdown:

          1 Reply Last reply
          0
          • N naouf10

            I just want to pass data to DataGridView from another form? I have 2 windows forms: - from1 contains DataGridView1 and button_frm1.The DataGridView have 3 columns and already have some data (6 rows) and DataGridView1 modifiers = Public. - form2 contains textBox1 and button_frm2. Now, when I click button_frm1 form2 appears and next when I click button_frm2 the value in the textBox should be inserted into DataGridView1 in column0 in the selected row. but instead, I got this error: "Index was out of range. Must be non-negative and less than the size of the collection". Please help me how to insert the textBox value from form2 into DataGridView1 in form1. What steps to follow? Thank you very much in advance. Here is the code I tried: Form1: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button_frm1_Click(object sender, EventArgs e) { Form2 frm2 = new Form2(); frm2.Show(); } } Form2: public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button_frm2(object sender, EventArgs e) { Form1 frm1 = new Form1(); textBox1.Text= frm1.dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); } }

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

            You can't. DataGridView are very arrogant and won't accept anything coming from someone else.

            Do not escape reality : improve reality !

            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