Having problems succuessfully populating the listBox via arrays. Array size is input by user. Also, cant quite get the SaveFileDialog working with the option for the user to create own filename & location.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace _7_3
{
public partial class Form1 : Form
{
//string[] studentData = null;
int arraySize = 0;
int counter = 0;
public Form1()
{
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string firstName = "";
string lastName = "";
firstName = Convert.ToString(textBoxFirstName.Text);
lastName = Convert.ToString(textBoxLastName.Text);
arraySize = Convert.ToInt32(textBoxSize.Text);
string[] studentData = new string[arraySize];
//send data to array
studentData[counter] = textBoxFirstName.Text;
studentData[counter] = textBoxLastName.Text;
counter++;
//clear textbox fields
textBoxLastName.Clear();
textBoxFirstName.Clear();
textBoxFirstName.Focus();
if (arraySize == counter)
{
MessageBox.Show("All students have been input.");
File.WriteAllLines("TextFile.txt", studentData);
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button2_Click(object sender, EventArgs e)
{
string[] textFile = File.ReadAllLines("TextFile.txt");
listBox1.DataSource = textFile.ToList();
}
private void button3_Click(object sender, EventArgs e)
{
SaveFileDialog Open = new SaveFileDialog();
}
}
}