我想确定用户是否已在组合框中输入了自己的值,如果他们在此输入了自己的值,则要执行某项操作。我在想是否可以不选择组合框索引...执行过程。我的组合框由包含很多项目的CSV文件填充。
我尝试了这个,但是没有用。程序崩溃。
private void cBxMake_TextChanged(object sender, EventArgs e)
{
string make;
string miles;
string usage;
string kept;
make = cBxMake.Text;
miles = cBxMiles.SelectedItem.ToString();
usage = cBxUsage.SelectedItem.ToString();
kept = cBxKept.SelectedItem.ToString();
// creating a DriverDetails object and sending it the data just used
VehicleDetails vehicleDets = new VehicleDetails(make, miles, usage, kept);
// add the object to the List
vehicleDet.Add(vehicleDets);
string date = DateTime.Today.ToString("dd-MM-yyyy"); //get today's date
string filePath = "Policy_Discuss_With_Customer" + date + ".csv"; //create a name of the new csv file (including the date)
string delimiter = ","; //comma needed to create new csv file
StringBuilder sb = new StringBuilder();
foreach (VehicleDetails vehicleDetails in vehicleDet) //go through the List called DriverDetails and examine each object in turn
{
sb.AppendLine(vehicleDets.Make + delimiter + vehicleDets.Miles + delimiter + vehicleDets.Usage + delimiter + vehicleDets.Kept);//uild up a String containing all the data in the List
}
//File.WriteAllText(filePath, sb.ToString());
File.AppendAllText(filePath, sb.ToString()); //add the new string (made up of multiple lines, each representing data from ONE order) to the end of the csv file
MessageBox.Show("Vehicle details saved to file, no premium calculated. Details will be discussed.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
var popUp = new addDriverConstraints();
popUp.Show();
}
ive删除了上面的代码
if (cBxMake.SelectedItem !(cBxMake.Items))
}
}
如果所选项目(即用户在组合bx中键入的内容)与项目列表不匹配,我想要这样的内容...