单元格的EditChange事件中加入下列代码:
int I = fpSpread1.Sheets[0].ActiveRowIndex;
string MaterialName = fpSpread1.Sheets[0].Cells[I, 8].Text;
if (MaterialName.Trim() != "")
{
SqlStr = "Select MaterialNo From MaterialList where MaterialName like '%" + MaterialName + "%'";
MyDataClass.con_open();
SqlDataAdapter Da = new SqlDataAdapter(SqlStr, DataClass.MyMeans.My_con);
DataSet Ds = new DataSet();
Da.Fill(Ds, "MaterialList");
if (Ds.Tables[0].Rows.Count > 0)
{
string[] cbstr = new string[Ds.Tables[0].Rows.Count];
for (int II = 0; II < Ds.Tables[0].Rows.Count; II++)
{
//fpSpread1.Sheets[0].Cells[I, J].Text = Ds.Tables[0].Rows[II]["DyeName"].ToString();
cbstr[II] = Ds.Tables[0].Rows[II]["MaterialName"].ToString();
}
ComboCell.Items = cbstr;
//展开列表
var combo = fpSpread1.EditingControl as FarPoint.Win.FpCombo;
combo.DroppedDown = true;
fpSpread1.Focus();//必须加此句,否则会激发窗体的Activated事件,不知原因?
}
Ds.Clone();
Ds.Dispose();
Da.Dispose();
}
为何没有触发事件?
窗体的load事件中:
fpSpread1.EditMode = true;
//指定自动完成的模式及数据源
ComboCell.Editable = true;//单元格允许编辑
ComboCell.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
ComboCell.AutoCompleteSource = AutoCompleteSource.ListItems;
fpSpread1.EditModePermanent = true;
fpSpread1.Sheets[0].Columns[0].CellType = ComboCell;
this.fpSpread1.ButtonDrawMode = FarPoint.Win.Spread.ButtonDrawModes.CurrentRow;//当前行显示下拉框 |