我想弄清楚如何檢查列表框是否包含特定的字符串在選定的索引,但我無法弄清楚。這是一個WAF項目。檢查列表框中選定的項目是否包含特定字符
private void UpdateGUI(string name, double price)
{
//Check if the seat is already reserved??
//Check if the seat is already canceled??
int index = lstSeats.SelectedIndex;
if (index < 0)
{
MessageBox.Show("Please select an item in the list!");
return;
}
string strOut = string.Empty;
string strReserved = "Vacant";
if (rbtnReserve.Checked)
{
strReserved = "Reserved";
}
else
{
name = string.Empty;
price = 0.0;
}
strOut = string.Format("{0,3} {1,14} {2,11} {3,13:f2}", index + 1, strReserved, name, price);
lstSeats.Items.RemoveAt(index);
lstSeats.Items.Insert(index, strOut);
lblNumOfReservedSeats.Text = numOfReservedSeats.ToString();
lblNumberOfVacantSeats.Text = (totalNumOfSeats - numOfReservedSeats).ToString();
lblTotalNumOfSeats.Text = totalNumOfSeats.ToString();
}
基本上,我不希望保留已被保留,或者已經座位被取消,我不想再取消它的座位(電影院)。有什麼建議麼?
或者倒不如在下面的代碼?:檢查
private void btnOK_Click(object sender, EventArgs e)
{
string name = string.Empty;
double price;
bool inputOK = ReadAndValidateInput(out name, out price);
if (inputOK)
{
if (rbtnReserve.Checked)
{
numOfReservedSeats++;
}
else
{
numOfReservedSeats--;
}
UpdateGUI(name, price);
}
}
的WinForms ,WPF或其他東西? – nawfal
也非常不清楚你想要什麼。哪些特定字符?你想在哪裏檢查它?哪條線?我的猜測是你應該做一些像'listbox.Text.Contains(...)'或類似的東西。 – nawfal
我建議爲你的目的定義一個座位類,並且在這個類中創建一個保留狀態和取消狀態的成員。 – HimBromBeere