Click here to Skip to main content
15,916,692 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Pointer trails Pin
obermd7-Nov-15 6:06
obermd7-Nov-15 6:06 
GeneralRe: Pointer trails Pin
harold aptroot5-Nov-15 8:01
harold aptroot5-Nov-15 8:01 
GeneralRe: Pointer trails Pin
Dan Neely5-Nov-15 8:28
Dan Neely5-Nov-15 8:28 
GeneralRe: Pointer trails Pin
Jörgen Andersson5-Nov-15 8:29
professionalJörgen Andersson5-Nov-15 8:29 
GeneralRe: Pointer trails Pin
MacSpudster5-Nov-15 9:34
professionalMacSpudster5-Nov-15 9:34 
GeneralRe: Pointer trails Pin
den2k885-Nov-15 21:30
professionalden2k885-Nov-15 21:30 
GeneralRe: Pointer trails Pin
fglenn6-Nov-15 8:08
fglenn6-Nov-15 8:08 
GeneralHow can I pass data to DataGridView from another form? Pin
naouf105-Nov-15 6:32
naouf105-Nov-15 6:32 
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();


}
}
GeneralRe: How can I pass data to DataGridView from another form? Pin
OriginalGriff5-Nov-15 6:35
mveOriginalGriff5-Nov-15 6:35 
GeneralRe: How can I pass data to DataGridView from another form? Pin
Maximilien5-Nov-15 6:49
Maximilien5-Nov-15 6:49 
GeneralRe: How can I pass data to DataGridView from another form? Pin
R. Giskard Reventlov5-Nov-15 7:06
R. Giskard Reventlov5-Nov-15 7:06 
GeneralRe: How can I pass data to DataGridView from another form? Pin
Rage5-Nov-15 7:19
professionalRage5-Nov-15 7:19 
GeneralHave you visited your user page recently? Pin
OriginalGriff5-Nov-15 6:10
mveOriginalGriff5-Nov-15 6:10 
GeneralRe: Have you visited your user page recently? Pin
Basildane5-Nov-15 6:30
Basildane5-Nov-15 6:30 
GeneralRe: Have you visited your user page recently? Pin
Suvendu Shekhar Giri5-Nov-15 9:43
professionalSuvendu Shekhar Giri5-Nov-15 9:43 
GeneralKorean spam.. Pin
PompeyThree5-Nov-15 5:57
PompeyThree5-Nov-15 5:57 
GeneralRe: Korean spam.. Pin
OriginalGriff5-Nov-15 6:16
mveOriginalGriff5-Nov-15 6:16 
GeneralRe: Korean spam.. Pin
R. Giskard Reventlov5-Nov-15 7:05
R. Giskard Reventlov5-Nov-15 7:05 
GeneralSpecification Software Pin
zephaneas5-Nov-15 5:35
zephaneas5-Nov-15 5:35 
GeneralRe: Specification Software Pin
Bassam Abdul-Baki5-Nov-15 5:54
professionalBassam Abdul-Baki5-Nov-15 5:54 
GeneralRe: Specification Software Pin
Rage5-Nov-15 6:08
professionalRage5-Nov-15 6:08 
GeneralAPOD Pin
R. Giskard Reventlov5-Nov-15 5:10
R. Giskard Reventlov5-Nov-15 5:10 
GeneralThought of the day Pin
OriginalGriff5-Nov-15 5:01
mveOriginalGriff5-Nov-15 5:01 
GeneralRe: Thought of the day Pin
H.Brydon5-Nov-15 5:06
professionalH.Brydon5-Nov-15 5:06 
GeneralRe: Thought of the day Pin
megaadam5-Nov-15 5:17
professionalmegaadam5-Nov-15 5:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.