Click here to Skip to main content
15,905,420 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#

C#
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 need same help. when i enter aaa in to txtName and txtPrice i want it to go to my listbox when i press the butten. in this private void btnOK_Click(object sender, EventArgs e) i know i can do a new and enter lstSeats.Items.Add(string.Format("\t\t{0} \t{1}",txtPrice.Text, txtName.Text)); in to it but then my error messafe dont work
Posted

1 solution

AutoCompleteExtender control to a TextBox in order to display auto-complete suggestions as you type.

UserInterace code as:
XML
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:TextBox ID="txtMovie" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender
    ID="AutoCompleteExtender1"
    TargetControlID="txtName"
    runat="server" />


Code Behind C# code as:
C#
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey) {
    string[] names = {"Brian", "Chris", "John", "William"};
    return (from m in names where m.StartsWith(prefixText,StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900