Listbox
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;
namespace booking
{
public partial class MainForm : Form
{
private double revenue = 0.0;
private const int totalNumOfSeats = 240;
private int numOfReservedSeats = 0;
public MainForm()
{
InitializeComponent();
InitializeGUI();
}
private void InitializeGUI()
{
rbtnReserve.Checked = true;
lstSeats.Items.Clear();
txtName.Text = string.Empty;
}
private bool ReadAndValidateName(out string name)
{
name = "";
if (txtName.Text.Length > 0)
{
name = txtName.Text;
return true;
}
else
{
MessageBox.Show("Enter Letters Only", "Invalid Character", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtName.Focus();
return false;
}
}
private bool ReadAndValidatePrice(out double price)
{
price = 0;
double converted;
converted = Convert.ToDouble(txtPrice.Text);
if (converted >= 0.0)
{
price = Double.Parse(txtPrice.Text);
return true;
}
else
{
MessageBox.Show("Enter Numbers Only", "Invalid Character", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtPrice.Focus();
return false;
}
}
private bool ReadAndValidateInput(out string name ,out double price)
{
return ReadAndValidateName(out name) & ReadAndValidatePrice(out price);
}
private void btnOK_Click(object sender, EventArgs e)
{
string costumerName = string.Empty;
double seatPrice = 0.0;
bool inputOk = ReadAndValidateInput(out costumerName, out seatPrice);
if (inputOk)
{
numOfReservedSeats++;
revenue += seatPrice;
}
}
Jag har 2 textboxar som jag skriver in namn och pris i som jag sen vill få in i min listbox men problemet är när jag lägger in det i listboxen så fungerar inte fel meddelanden. Felmeddelanden ska komma när jag inte skriver in något i textboxarna och trycker på knappen. någon som kan berätta hur jag lättast får in listboxen i btnOK_Click så att faktiskt felmeddelanden kommer med också