TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
johan s
NA
8
2.9k
Get it in to listbox
Feb 27 2012 3:18 PM
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 label1_Click(object sender, EventArgs e)
{
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
private void txtPrice_TextChanged(object sender, EventArgs e)
{
}
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;
}
}
private void txtName_TextChanged(object sender, EventArgs e)
{
}
private void lstSeats_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void txtPrice_TextChanged_1(object sender, EventArgs e)
{
}
private void rbtnReserve_CheckedChanged(object sender, EventArgs e)
{
txtName.Enabled = true;
txtPrice.Enabled = true;
btnOK.Enabled = true;
}
private void rbtnCancel_CheckedChanged(object sender, EventArgs e)
{
txtName.Enabled = false;
txtPrice.Enabled = false;
btnOK.Enabled = false;
}
}
}
I wondering if anyone can help me to get it in to a listbox when i click on a button. I know i can do like lstSeats.Items.Add(string.Format("\t\t{0} \t{1}", txtPrice.Text, txtName.Text)); but then the error massage never com up so thats way i need help whit it on the butten i have know and the code in it
Reply
Answers (
0
)
Where do you look for up to date information?
Help with a console app