使用Combobox的selectedIndexChange填充Access数据库中的文本框。
我尝试过使用以下内容:
txtEventDate.Text = cboEventName.SelectedValue.ToString();
但它不会从所选数据中填写。
// clear out listbox
cboEventName.Items.Clear();
// create instance of class
clsData myData = new clsData();
// send SQL statement to class
myData.SQL = "SELECT ID, EventName, EventDate FROM tblEvents ORDER BY EventName";
// loop through datatable to get values
for (int i = 0; i < myData.dt.Rows.Count; i++)
{
// add customer to list box
cboEventName.Items.Add(myData.dt.Rows[i]["EventName"].ToString());
// add customer id to list
string eventdate = ["EventDate"].ToString();
txtEventDate.Text = cboEventName.SelectedValue.ToString();
// txtEventDate trying to fill from combobox entry and it isn't showing the date from the access.
intEventID.Add(int.Parse(myData.dt.Rows[i]["ID"].ToString()));
}
尝试这样设置EventDate for Selected Index值。如果SelectedValue与MyData Row Index匹配,则设置事件日期。
for (int i = 0; i < myData.dt.Rows.Count; i++)
{
// add customer to list box
cboEventName.Items.Add(myData.dt.Rows[i]["EventName"].ToString());
// add customer id to list
if(cboEventName.SelectedValue.ToString() ==myData.dt.Rows[i]["EventName"].ToString())
string eventdate = ["EventDate"].ToString();
txtEventDate.Text = cboEventName.SelectedValue.ToString();
}