Home > Enterprise >  how to pass input data from one form to another form C#, WinForms, wpf,
how to pass input data from one form to another form C#, WinForms, wpf,

Time:01-13

help, it's not possible in the AddGame form to transfer the entered data from the Textboxes to the listview1 table which is in the MainWindow form. error shows listview1 is not accessible due to security level

add form your text

 public partial class AddGame : Form
    {
        public MainWindow mainWindow;
        TextBox[] textBoxes; 
        public AddGame()
        {
            InitializeComponent();

        }
            public void setForm1(MainWindow form)
        {
            mainWindow = form;
        }
        private void AddGame_Load(object sender, EventArgs e)
        {
        }
        private void CloseAddFormButton_Click(object sender, EventArgs e)
        {
            Close();
        }
        public void Add0Batchbutton_Click(object sender, EventArgs e)
        {
            try
            {
                // Check to see if there are any blank texts, we can't be having those.
                if (Play0NametextBox.Text == string.Empty)
                    throw new System.ArgumentException("");
                if (PlayersTextBox.Text == string.Empty)
                throw new System.ArgumentException("");
                if (Sequence1TextBox.Text == string.Empty)
                 throw new System.ArgumentException("");
                if (Sequance2TextBox.Text == string.Empty)
                throw new System.ArgumentException("");
                if(CommentsTextBox.Text == String.Empty)
                throw new System.ArgumentException("");
            if(WinnerTextBox.Text ==  String.Empty)
                throw new System.ArgumentException("");
            if(GameDateTextBox.Text == string.Empty)
                throw new System.ArgumentException("");

            // Use the info given via textbox's and add them to items/subitems
            ListViewItem lvi = new ListViewItem(Play0NametextBox.Text);
            lvi.SubItems.Add(PlayersTextBox.Text);
            lvi.SubItems.Add(Sequence1TextBox.Text);
            lvi.SubItems.Add(Sequance2TextBox.Text);
            lvi.SubItems.Add(CommentsTextBox.Text);
            lvi.SubItems.Add(WinnerTextBox.Text);
            lvi.SubItems.Add(GameDateTextBox.Text);
            // Add the items to the list view.

            mainWindow.listView1.Items.Add(lvi); // here the error is that listview1 is not      accessible due to its security level

            // If no error, success.
            MessageBox.Show("");
            Close();
        }
        catch (Exception ex)
        {
            //If error show the error
            MessageBox.Show(ex.Message, "Error");
        }
    }
}

main form

  public partial class MainWindow : Form
{
    public MainWindow()
    {
        InitializeComponent();
    }
    private void Form1_Load(object sender, EventArgs e)
    {
    }
    private void AddGamesButton_Click(object sender, EventArgs e)
    {
        var addGames = new AddGame();
        addGames.Show();
    }
    private void Closebutton_Click(object sender, EventArgs e)
    {
        Close();
    }
    public void listView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        foreach (ListViewItem item in listView1.Items)
            item.ForeColor = Color.Gray;
    }
    private void DeleteButton_Click(object sender, EventArgs e)
    {
        int selectNumber = -1;
        foreach (ListViewItem item in listView1.Items)
            if (item.Selected)
            {
                selectNumber = int.Parse(item.Text);
            }
    }
}

I do not know what to do I'm lost what functions and methods I have some idea how to link this in SQl but thinking it won't work

  • Related