从文本框到列表框 [英] textbox to listbox by butten

查看:67
本文介绍了从文本框到列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


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;
        }

    }
}




我需要同样的帮助.当我在txtName和txtPrice中输入aaa时,当我按下按钮时,我希望它进入我的列表框.在这个私有的btnOK_Click(object sender,EventArgs e)中,我知道我可以做一个新操作并输入lstSeats.Items.Add(string.Format("\ t \ t {0} \ t {1}",txtPrice.Text, txtName.Text));进入它,但是我的错误messafe不起作用




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

推荐答案

AutoCompleteExtender控件到文本框,以便在键入时显示自动完成建议.

UserInterace代码为:
AutoCompleteExtender control to a TextBox in order to display auto-complete suggestions as you type.

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

    ID="AutoCompleteExtender1"

    TargetControlID="txtName"

    runat="server" />



C#代码后面的代码为:



Code Behind C# code as:

[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();
}


这篇关于从文本框到列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆