0

I have two form in my project, Form1 and Form2. In Form1 is a datagridview and a button, like shown in this pic:

Form1

If click button1 in Form1, it will show Form2. In Form2 there is a second button. I want to remove the last item in listview on Form1 if I click the button on form2.

Form1 code:

private void button1_Click(object sender, EventArgs e)
{
    Form2 fm = new Form2(dataGridViewData);
    fm.ShowDialog();
}

Form2 code :

private void button1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < dataGridViewData.SelectedRows - 1; i++)
        {
            dataGridViewData.Rows.Remove(dataGridViewData.SelectedRows[i]);
        }
        this.Close();
    }
olsn
  • 16,644
  • 6
  • 59
  • 65
Underdog
  • 129
  • 13
  • It seems that you are having difficulties with passing that `dataGridViewData` to `Form2`? Am I right? If it is so, then you can take a look at http://stackoverflow.com/questions/4587952/passing-data-between-forms, http://stackoverflow.com/questions/17836398/passing-values-between-windows-forms-c-sharp, https://msdn.microsoft.com/en-us/library/ms171925.aspx – Eugene Podskal Jun 25 '16 at 14:39
  • Look at http://stackoverflow.com/questions/32916215/c-sharp-add-label-from-form2/32916403#32916403, here I answered how to access controls from another form. – Paviel Kraskoŭski Jun 25 '16 at 14:47
  • @EugenePodskal thanks for your suggestion. but is not that used to get the value of the listbox and textbox? what if applied in datagridview ? . – Underdog Jun 25 '16 at 15:42
  • @Underdog I doubt that there is anything radically different between dealing with one or another type of control in such a manner. If it is nonetheless so, then tell us the exact issues. – Eugene Podskal Jun 25 '16 at 15:46
  • Check the comment here http://stackoverflow.com/questions/21162871/delete-last-row-in-datagridview – Jim Hewitt Jun 25 '16 at 15:47

0 Answers0