Reading a csv and placing data in a Listbox - c#

using System.IO;
namespace HW10
{
struct Employee
{
public string LastName;
public string FirstName;
public string IDNumber;
public string Department;
public string Position;
public string PayType;
public double HoursWorked;
public double PayRate;
}
public partial class frmPayroll : Form
{
//Create a list to hold the data from the input file
private List<Employee> EmployeeList = new List<Employee>();
public frmPayroll()
{
InitializeComponent();
}
private void frmPayroll_Load(object sender, EventArgs e)
{
}
private void btnOpen_Click(object sender, EventArgs e)
{
//Declare local variables
DialogResult ButtonClicked;
string InputRecord;
string[] InputFields;
Employee worker;
//Show the OpenFileDialog box for user to select file
openFileDialog1.InitialDirectory = Environment.CurrentDirectory;
openFileDialog1.FileName = "Payroll.csv";
ButtonClicked = openFileDialog1.ShowDialog();
if(ButtonClicked == DialogResult.Cancel)
{
MessageBox.Show("You did NOT select a file.");
return;
}
//Declare the streamreader variable to access the file
StreamReader inputFile = File.OpenText(openFileDialog1.FileName);
//Set up a loop to read every record, skipping the first record
InputRecord = inputFile.ReadLine();
while(!inputFile.EndOfStream)
{
InputRecord = inputFile.ReadLine();
InputFields = InputRecord.Split(',');
worker.LastName = InputFields[0];
worker.FirstName = InputFields[1];
worker.IDNumber = InputFields[2];
worker.Department = InputFields[3];
worker.Position = InputFields[4];
worker.PayType = InputFields[5];
worker.HoursWorked = double.Parse(InputFields[6]);
worker.PayRate = double.Parse(InputFields[7]);
//Add this worker struc to the list declared above
EmployeeList.Add(worker);
//Display the name in the Listbox on the form
listPayroll.Items.Add(worker.LastName + "," + worker.FirstName);
}
//Close the input file
inputFile.Close();
btnOpen.Enabled = false;
}
private void btnCompute_Click(object sender, EventArgs e)
{
listPayroll.Items.Clear();
string DisplayHeader = String.Format("{0,-18}{1,14}{2,11}{3,13}",
"Employee", "HoursWorked", "PayRate", "Gross Pay");
listPayroll.Items.Add(DisplayHeader);
DisplayHeader = String.Format("{0,-18}{1,14}{2,11}{3,13}",
"Employee", "HoursWorked", "PayRate", "Gross Pay");
listPayroll.Items.Add(DisplayHeader);
foreach (Employee emp in EmployeeList)
{
double HoursWorked = 0.0;
double PayRate = 0.0;
double GrossPay = 0.0;
// Check for Salary or Hourly
if(emp.PayType == "Hourly")
{
if(emp.HoursWorked > 40.0)
{
PayRate = emp.PayRate * (emp.HoursWorked - 40.0);
HoursWorked = emp.PayRate * 40.0;
}
else
{
PayRate = 0.0;
HoursWorked = emp.PayRate * emp.HoursWorked;
}
}
else //Salary paytype. No ot. Just striaght pay for 40 hrs
{
PayRate = 0.0;
HoursWorked = emp.PayRate * 40.0;
}
GrossPay = HoursWorked + PayRate;
//Display this data in the listbox
string DisplayPayroll = String.Format("{0,-18}{1,14:c}{2,11:C{3,13:c}",
emp.FirstName + " " + emp.LastName,
HoursWorked, PayRate, GrossPay);
listPayroll.Items.Add(DisplayPayroll);
}
}
private void btnExit_Click(object sender, EventArgs e)
{
// This method closes the application
this.Close();
I'm having issues when trying to compute data from a .csv file to a listbox. It's throwing an Exception unhandled error in the "Display this data in the listbox" block of code. I've place the System IO and all the strings/double that I need to show up in the list box. I'm sure this is a very simple fix but I'm new to coding. Any help would be greatly appreciated.

Using string.Split(',') isn't enough to handle CSV data. The CSV data can include fields that have commas in them:
https://en.wikipedia.org/wiki/Comma-separated_values
I'd suggest a CSV library to help parse the file. Google search of "c# csv library" should give you lots of options.

Related

Not sure why this Radio Button is throwing an error?

I am currently making a fitness class booking system for some study I am doing so please bare with me.
I have done most of the code but I am having this strange issue with my 2nd radio button for selecting what class you want.
I have set up my code so a message box appears if the Member ID you have entered is already registered to the fitness class you have selected. For my RadioButton1 (rbCardioClass) and RadioButton2 (rbPilatesClass), the error message box works great and works as it should. But my RadioButton2 (rbSpinClass) will make the error message box appear everytime, even if the MemberID is not associated to the 'Spin Class'.
I have tried different uses of if statements, different radio buttons etc but can't seem to get it to work the way I want.
If I go to my servicesErrorCheck(string[] description)method and just the temp variable to true all radio buttons save to the database table correctly BUT I then lose my erroring, which makes me thinks it is something to do with the way I have set up the message box, maybe.
Here is a screenshot of the prototype form just for reference. FitnessClassBooking Form
Here is a screenshot of the table while the app is running App Running Fitness Form
Here is the error being thrown with MemberID that has no 'Spin' class associated with it App Running Error
Here is my code in question -
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace Membership_Formv2
{
public partial class FitnessClassBooking : Form
{
public FitnessClassBooking()
{
InitializeComponent();
}
private void bMainMenu_Click(object sender, EventArgs e)
{
new MainMenu().Show();
this.Hide();
}
private void fitnessInformationBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.fitnessInformationBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.databaseDataSet);
}
private void FitnessClassBooking_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'databaseDataSet.Members' table. You can move, or remove it, as needed.
this.membersTableAdapter.Fill(this.databaseDataSet.Members);
// TODO: This line of code loads data into the 'databaseDataSet.FitnessInformation' table. You can move, or remove it, as needed.
this.fitnessInformationTableAdapter.Fill(this.databaseDataSet.FitnessInformation);
}
private void fitnessInformationDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private string descriptionfit()
{
string className = "";
if (rbCardioClass.Checked == true)
{
className = "Cardio";
}
else if (rbSpinClass.Checked == true)
{
className = "Spin";
}
else if (rbPilatesClass.Checked == true)
{
className = "Pilates";
}
return className;
}
private string classDescription()
{
string serviceSeletionString = "Class";
if (rbCardioClass.Checked == true)
{
serviceSeletionString = rbCardioClass.Text;
this.Refresh();
}
else if (rbSpinClass.Checked == true)
{
serviceSeletionString = rbSpinClass.Text;
this.Refresh();
}
else if (rbPilatesClass.Checked == true)
{
serviceSeletionString = rbPilatesClass.Text;
this.Refresh();
}
return serviceSeletionString;
}
private bool errorCheckingID()
{
bool statusDB = true;
//Getting row info from MembersTa table
DatabaseDataSet.MembersRow newEntry = databaseDataSet.Members.FindByMemberID(Int32.Parse(textBox3.Text));
//Getting information from BookingTa table
if (newEntry == null)
{
statusDB = false;
return (statusDB);
}
return (statusDB);
}
public bool servicesErrorCheck(string[] description)
{
bool temp = true;
string serviceSeletionString = "";
if (rbCardioClass.Checked == true)
{
serviceSeletionString = rbCardioClass.Text;
this.Refresh();
}
else if (rbSpinClass.Checked == true)
{
serviceSeletionString = rbSpinClass.Text;
this.Refresh();
}
else if (rbPilatesClass.Checked == true)
{
serviceSeletionString = rbPilatesClass.Text;
this.Refresh();
}
for (int t = 0; t < description.Length; t++)
{
if (serviceSeletionString.Contains(description[t].Trim()))
{
temp = false;
break;
}
}
return (temp);
}
private string originalaccesdb()
{
string a = "";
DatabaseDataSet.FitnessInformationRow newRow = databaseDataSet.FitnessInformation.NewFitnessInformationRow();
newRow.Fitness_Booking_ID = databaseDataSet.FitnessInformation.Count + 1;
newRow.Description = descriptionfit();
newRow.MemberID = Int32.Parse(textBox3.Text);
databaseDataSet.FitnessInformation.AddFitnessInformationRow(newRow);
return a;
}
private string[] accessDB()
{
int t = 0;
int temp;
string[] servicesList = { "n", "n", "n" }; //This variable will store the data
//Same code too extract table information
foreach (DataRow r in databaseDataSet.FitnessInformation.Rows)
{
temp = Int32.Parse(r["MemberID"].ToString());
if (temp == Int32.Parse(textBox3.Text))
{
//Store inside the array all the services/description against the ID.
//Note that this array will remain "" for all the elements inside the array
//if no descritopn/services (i.e., record) is found against the input ID
servicesList[t] = r["Description"].ToString();
t = t + 1;
}
}
return (servicesList);
}
private void button1_Click(object sender, EventArgs e)
{
string text = textBox1.Text;
textBox1.Text = "";
int a = Int32.Parse(textBox2.Text);
DatabaseDataSet.MembersRow newID = databaseDataSet.Members.FindByMemberID(Int32.Parse(textBox2.Text));
string booking = "";
int temp;
foreach (DataRow r in databaseDataSet.FitnessInformation.Rows)
{
temp = Int32.Parse(r["MemberID"].ToString());
if (temp == Int32.Parse(textBox2.Text))
{
booking = r["Description"].ToString() + ", " + booking;
}
}
textBox1.Text = "Member ID is: " + (newID.MemberID).ToString() + Environment.NewLine +
"First Name is: " + (newID.First_Name).ToString() + Environment.NewLine +
"Last Name is: " + (newID.Last_Name).ToString() + Environment.NewLine +
"Bookings: " + booking;
}
public void button2_Click(object sender, EventArgs e)
{
bool status1, status2;
string[] description;
//Error control at the outer level for valid ID
status1 = errorCheckingID();
//Proceed only if ID is valid or status1 is true
if (status1)
{
//Retrieve information from the other database. Ideally you want this method to return
//an array containing registered services. This would be an array of strings.
description = accessDB();
//Services error checking
status2 = servicesErrorCheck(description);
//Now this is the code that would call the method to save data ito database
//when status2 and 2 are true
if (status2)
{
//Code for saving into database.
DatabaseDataSet.FitnessInformationRow newRow = databaseDataSet.FitnessInformation.NewFitnessInformationRow();
newRow.Fitness_Booking_ID = databaseDataSet.FitnessInformation.Count + 1;
newRow.Description = classDescription();
newRow.MemberID = Int32.Parse(textBox3.Text);
databaseDataSet.FitnessInformation.AddFitnessInformationRow(newRow);
}
else
{
//Show error that this service is not available
MessageBox.Show("This Class is already assigned to that Member ID");
}
}
else
{
//Error message invalid ID
MessageBox.Show("Invalid ID");
}
}
private void radioButton1_Click(object sender, EventArgs e)
{
}
private void radioButton4_Click(object sender, EventArgs e)
{
}
private void radioButton3_Click(object sender, EventArgs e)
{
}
}
}
I am really not sure why this is happening so I would really appreciate any help.
You are checking each string in descriptions as follows:
serviceSeletionString.Contains(description[t].Trim())
which considering at least one of the strings is just n it will always match Spin.
Quite why you are always returning an array with the blank ones having n, I don't know. Personally I would just use a List<string> and Add each item from the database to it. But that is a separate point.
Either change it to serviceSeletionString == description[t] (don't see why you need Trim()) or just replace the whole foreach loop with description.Contains(serviceSeletionString)

trying to read some data from a csv file c#

Im trying to read some data from a csv file and display it in c#
this works fine but i have 2 different rows in my csv file which i'll be adding too.
I want them to be accessible if say someonet types '1' into the ukNumber field it will pull all of their data.
atm no matter what i type it always displays the last line in my csv file.
namespace Appraisal
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void ukNumber_TextChanged(object sender, EventArgs e)
{
}
public void search_Click(object sender, EventArgs e)
{
using (var reader = new StreamReader(File.OpenRead("C:\\Users\\hughesa3\\Desktop\\details.csv"),
Encoding.GetEncoding("iso-8859-1")))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
string idStr = values[0];
string firstnameStr = values[0];
string surnameStr = values[0];
string jobroleStr = values[0];
string salaryStr = values[0];
richTextBox1.Text = "Name: " + values[1] + "\nSurname: " + values[2] + "\nJob Role: " + values[3] + "\nSalary: £" + values[4];
}
}
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void apprasialCode_TextChanged(object sender, EventArgs e)
{
}
private void apprasialBtn_Click(object sender, EventArgs e)
{
}
private void ukNumberLabel_Click(object sender, EventArgs e)
{
}
}
}
There is a CsvHelper available via Nuget
https://www.nuget.org/packages/CsvHelper/
See following question:
using csvhelper (nuGET) with C# MVC to import CSV files
to read data from csv file:
using (var reader = new StreamReader(File.OpenRead("c:/yourfile.csv"),
Encoding.GetEncoding("iso-8859-1")))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';'); // replace ';' by the your separator
string idStr = values[0];
string firstnameStr = values[0];
string surnameStr = values[0];
string jobroleStr = values[0];
string salaryStr = values[0];
//convert string
}
}

Why doesn't my class write to a text file?

Here is my AddReservation Form code. Notice that I call the Piper.WritePiper() method and pass in the Name and Seat that the user enters. I'm not sure why this isn't working. I'm not getting any errors or anything. I am simply just wanting a user to be able to enter their name and seat that they would like to take on the plane and then update the file. Please tell me what I am doing wrong... Thank you in advance!!
public partial class frmAddReservation : Form
{
public frmAddReservation()
{
InitializeComponent();
}
List<Seating> piperSeating = new List<Seating>();
List<Seating> cessnaSeating = new List<Seating>();
private void frmAddReservation_Load(object sender, EventArgs e)
{
piperSeating = Piper.GetPiperReservations();
cessnaSeating = Cessna.GetCessnaReservations();
}
private void btnShowPiper_Click(object sender, EventArgs e)
{
listFlight.Items.Add("Piper Seating Chart:");
listFlight.Items.Add("");
//loop through all the seats
foreach (Seating plane in piperSeating)
{
// add the name of plane to the listbox
listFlight.Items.Add(plane.Name + " " + plane.Seat);
}
}
private void btnAddPiper_Click(object sender, EventArgs e)
{
string Name;
int Seat;
if (DataValid())
{
Name = txtName.Text;
Seat = Convert.ToInt16(txtSeat.Text);
Piper.WritePiper(Name, Seat);
}
}
private bool DataValid()
{
bool isOK = false;
if (CheckSeat(txtSeat))
{
isOK = true;
}
return isOK;
}
private bool CheckSeat(TextBox tbox)
{
bool isOK = true;
try
{
Convert.ToDouble(tbox.Text);
}
catch
{
isOK = false;
}
return isOK;
}
}
Here is my Piper.cs class:
public static class Piper
{
private const string dir = #"Z:\Desktop\Windows 7 Files\C#.net\Reservations\Reservations\Reservations\";
private const string path = dir + "PiperDat.txt";
public static List<Seating> GetPiperReservations()
{
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
StreamReader textIn =
new StreamReader(
new FileStream(path, FileMode.Open, FileAccess.Read));
List<Seating> personList = new List<Seating>();
while (textIn.Peek() != -1)
{
string row = textIn.ReadLine();
string[] columns = row.Split(',');
Seating person = new Seating();
person.Name = columns[0];
person.Seat = Convert.ToInt16(columns[1]);
personList.Add(person);
}
textIn.Close();
return personList;
}
public static void WritePiper(string Name, int Seat)
{
List<Seating> piperSeating = new List<Seating>();
piperSeating = Piper.GetPiperReservations();
StreamWriter textOut =
new StreamWriter(
new FileStream(path, FileMode.Open, FileAccess.Write));
foreach (Seating plane in piperSeating)
{
Name = plane.Name;
Seat = plane.Seat;
textOut.Write(Name + ",");
textOut.WriteLine(Seat);
}
}
}
Look at the WritePiper method.
It just reads the file and then writes it back, without any changes. The values in the parameters are ignored, the parameters are just used as temporary storage for the data when it is written to the file.
You need to include the values in the parameters as an item, either by adding it to the list, or by writing it to the file along with the items in the list.
Example:
Seating person = new Seating();
person.Name = Name;
person.Seat = Seat;
piperSeating.Add(person);
I think the cause of your issue might be having forgotten the closure of the file, in alternative you might force the text to flush with textOut.Flush().
Try adding textOut.Close() at the end of the WritePiper(...) method.

How do you add items to a listbox on a second form?

Working on a project for school that has 2 forms. I want to add items to the listbox in the Display form when I click the show data button. It's showing the form but the form is blank. I think this is because the form object is being created 2x once when I click the add button and another when I click the show data button. How can I create a new object of the display form that can be used in any method in my main form?
Sorry there is a few things in here that I am still working on that were just ideas. I am a beginner so please keep the help in simple terms if at all possible. Thanks :)
private void addEmployee(Employee newEmployee)
{
//Get data from textboxes and use set methods in employee class
newEmployee.Name = EmployeeNameTextBox.Text;
newEmployee.BirthDate = EmployeeBirthDateTextBox.Text;
newEmployee.Dept = EmployeeDeptTextBox.Text;
newEmployee.HireDate = EmployeeHireDateTextBox.Text;
newEmployee.Salary = EmployeeSalaryTextBox.Text;
}
private void AddButton_Click(object sender, EventArgs e)
{
//New list for employee class objects - employeelist
List<Employee> employeeList = new List<Employee>();
//Create new instance of Employee class - newEmployee
Employee newEmployee = new Employee();
bool errorCheck = false;
CheckForms(ref errorCheck);
if (!errorCheck)
{
//Gather input from text boxes and pass newEmployee object
addEmployee(newEmployee);
//Add object to employeeList
employeeList.Add(newEmployee);
Display myDisplay = new Display();
myDisplay.OutputListBox.Items.Add(" Bob");
//" " + newEmployee.BirthDate + " " +
//newEmployee.Dept + " " + newEmployee.HireDate + " " + newEmployee.Salary);
You are creating two separate instances of mydisplay.Create a single instance when the Form Loads and refer to that when you call ShowDataButton_Click
namespace WK4
{
public partial class MainForm : Form
{
Display myDisplay;
public MainForm()
{
InitializeComponent();
}
//Method to clear form input boxes
private void ClearForm()
{
EmployeeNameTextBox.Text = "";
EmployeeBirthDateTextBox.Text = "";
EmployeeDeptTextBox.Text = "";
EmployeeHireDateTextBox.Text = "";
EmployeeSalaryTextBox.Text = "";
FooterLabel.Text = "";
}
//Method to check for blank input on textboxes
private void CheckForms(ref bool error)
{
if (EmployeeNameTextBox.Text == "" || EmployeeBirthDateTextBox.Text == "")
{
MessageBox.Show("Please do not leave any fields blank");
error = true;
}
else if (EmployeeDeptTextBox.Text == "" || EmployeeHireDateTextBox.Text == "")
{
MessageBox.Show("Please do not leave any fields blank");
error = true;
}
else if (EmployeeSalaryTextBox.Text == "")
{
MessageBox.Show("Please do not leave any fields blank");
error = true;
}
else
error = false;
}
private void addEmployee(Employee newEmployee)
{
//Get data from textboxes and use set methods in employee class
newEmployee.Name = EmployeeNameTextBox.Text;
newEmployee.BirthDate = EmployeeBirthDateTextBox.Text;
newEmployee.Dept = EmployeeDeptTextBox.Text;
newEmployee.HireDate = EmployeeHireDateTextBox.Text;
newEmployee.Salary = EmployeeSalaryTextBox.Text;
}
private void AddButton_Click(object sender, EventArgs e)
{
//New list for employee class objects - employeelist
List<Employee> employeeList = new List<Employee>();
//Create new instance of Employee class - newEmployee
Employee newEmployee = new Employee();
bool errorCheck = false;
CheckForms(ref errorCheck);
if (!errorCheck)
{
//Gather input from text boxes and pass newEmployee object
addEmployee(newEmployee);
//Add object to employeeList
employeeList.Add(newEmployee);
Display myDisplay = new Display();
myDisplay.OutputListBox.Items.Add(" Bob");
//" " + newEmployee.BirthDate + " " +
//newEmployee.Dept + " " + newEmployee.HireDate + " " + newEmployee.Salary);
//Clear Form after adding data
ClearForm();
//Print footer employee saved info
FooterLabel.Text = ("Employee " + newEmployee.Name + " saved.");
}
}
//Exit the form/program
private void ExitButton_Click(object sender, EventArgs e)
{
this.Close();
}
//Method to clear the form and reset focus
private void ClearButton_Click(object sender, EventArgs e)
{
ClearForm();
EmployeeNameTextBox.Focus();
}
private void ShowDataButton_Click(object sender, EventArgs e)
{
myDisplay.ShowDialog();
}
private void MainForm_Load(object sender, EventArgs e)
{
myDisplay = new Display();
}
}
}
You are making 2 different instances of display class, in first instance you are adding data and you are displaying it using the second instance thats why you are getting a blank form
create a display class object on your MainForm_Load
private void MainForm_Load(object sender, EventArgs e)
{
Display myDisplay = new Display();
}
and the use this object (myDisplay) to add and display data in your AddButton_Click and ShowDataButton_Click methods respectively.

Display all listview items in messagebox c#

I have a listview with subitems. The first 5 sub items are the name, items, total price, address and telephone.
The rest of the subitems contain the past list that I displayed for my order.
It is a pizzeria program and I want it to be able to get the customers info and order.
I can get the info but can't get the rest of the order.
I'm wondering how I can display the rest of my order if that makes sense.
Example Order:
Name: Claud
Items: 3
Total: 10.99
Address: (Blank)
Telephone: (Blank)
Order: Small Pizza
-Bacon
BreadSticks
Right now my messagebox looks like this:
Name: Claud
Items: 3
Total: 10.99
Address: (Blank)
Telephone: (Blank)
Order: Small Pizza
So I just want it to display the -Bacon and BreadSticks.
Source Code:
private void CustomerInfo_Click(object sender, EventArgs e)
{
ListViewItem customers = new ListViewItem(fullName.Text);
customers.SubItems.Add(totalcount.ToString());
customers.SubItems.Add(total.ToString());
customers.SubItems.Add(Address.Text);
customers.SubItems.Add(telephone.Text);
for (int i = 0; i < OrderlistBox.Items.Count; i++)
{
customers.SubItems.Add(OrderlistBox.Items[i].ToString());
}
Customers.Items.Add(customers);
MessageBox.Show("Sent order for " + fullName.Text.ToString() + " to screen.");
//CLEAR ALL FIELDS
OrderlistBox.Items.Clear();
fullName.Text = "";
Address.Text = "";
telephone.Text = "";
totalDue.Text = "";
totalItems.Text = "";
}
private void customerInformationToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Customers.SelectedItems.Count != 0)
{
MessageBox.Show("Name: " + Customers.SelectedItems[0].SubItems[0].Text + "\n" +
"Adress: " + Customers.SelectedItems[0].SubItems[3].Text + "\n" +
"Telephone: " + Customers.SelectedItems[0].SubItems[4].Text + "\n" +
"Order: " +Customers.SelectedItems[0].SubItems[5].Text);
}
}
You can create custom message box by creating new winform that act as your messagebox.
Create public property on it to pass the value of your selecteditems something like:
Then on your form :
private void customerInformationToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Customers.SelectedItems.Count != 0)
{
var myformmessagedialog = new MyFormMessageDialog
{
name = Customers.SelectedItems[0].SubItems[0].Text,
adress=Customers.SelectedItems[0].SubItems[3].Text,
telephone=Customers.SelectedItems[0].SubItems[4].Text
};
myformmessagedialog.ShowDialog();
}
}
Your MessageBoxDialogform:
MyFormMessageDialog : Form
{
public MyFormMessageDialog()
{
InitializeComponent();
}
public string name;
public string adress;
public string telephone;
private void MyFormMessageDialog_Load(object sender, EventArgs e)
{
lblName.Text = name;
lbladdress.Text = adress;
telephone.Text telephone;
//if you are saving ado.net stuff
//query username where name = name then bind it on a list box or a combo box
var Orderdata = //you retrieve info via DataTable;
lstOder.Items.Clear();
foreach (DataRow data in Orderdata.Rows)
{
var lvi = new ListViewItem(data["Order"].ToString());
// Add the list items to the ListView
lstlstOder.Items.Add(lvi);
}
}
}
Hope this help you.
Regards

Categories