我用tabcontrol用了三个tabpage,绑定了三个datagrid,pageA的datagrid的选出的数据作pageB的datagrid数据的参数,pageB的datagrid选出的数据作pageC的datagrid数据的参数,现在出现此问题,pageA→pageB→pageC依次按正常,datagrid都能正常显示,但pageA→pageC就不能显示,非要点一下pageB,但我是一起数据绑定和更新的?private void tab_Inform_SelectedIndexChanged(object sender, System.EventArgs e)
{
// //if userid is changed,update databind
if(this.txtGuid.Text!="")
{
if(Firsthit)
{
UserID=this.txtGuid.Text;
DataBindlist();
//判断是否是首次绑定
Firsthit=false;
}
else
{
DataBindlist();
}
//获得当前TabNum
TabNum=this.tab_Inform.SelectedIndex.ToString();
}
} private void DataBindlist()
{
string Sql;
dsAll=new DataSet();
try
{
if(CN.State ==ConnectionState.Closed)
{
CN.Open();
}
//首次全部重新绑定,否则判断UserID相同
if(Firsthit||(TabNum=="0"&&UserID!=this.txtGuid.Text))
{
if(UserID!=this.txtGuid.Text)
{
UserID=this.txtGuid.Text;
}
Sql="select UserProduct.*,Model,ModelAlias from UserProduct ";
Sql+="inner join MachineModel on UserProduct.ModelID=MachineModel.ModelID ";
Sql+="where UserID='"+UserID+"'";
// MessageBox.Show(Sql);
adpMachine=new SqlDataAdapter(Sql,CN);
dsAll=new DataSet();
adpMachine.Fill(dsAll,"Product");

if(Firsthit)
{
dtMachine=dsAll.Tables["Product"];
AddProductDataTableStyle();
} this.dgProduct.DataSource=null;
this.dgProduct.DataSource=dsAll;
this.dgProduct.DataMember="Product";
CurrencyManager cmProduct=(CurrencyManager)this.BindingContext[dgProduct.DataSource,dgProduct.DataMember];
((DataView)cmProduct.List).AllowNew=false;
((DataView)cmProduct.List).AllowDelete=false;
((DataView)cmProduct.List).AllowEdit=false; this.txt_Serial.DataBindings.Clear();
this.txt_Serial.Text="";
this.txt_Serial.DataBindings.Add("Text",dsAll,"Product.MachineID");
this.txt_Voice.DataBindings.Clear();
this.txt_Voice.Text="";
this.txt_Voice.DataBindings.Add("Text",dsAll,"Product.InvoiceNO");
this.txtPrice.DataBindings.Clear();
this.txtPrice.Text="";
this.txtPrice.DataBindings.Add("Text",dsAll,"Product.Price");
this.txtShop.DataBindings.Clear();
this.txtShop.Text="";
this.txtShop.DataBindings.Add("Text",dsAll,"Product.Shop");
this.cmb_Model.DataBindings.Clear();
this.cmb_Model.SelectedIndex=0;
this.cmb_Model.DataBindings.Add("SelectedValue",dsAll,"Product.ModelID");
this.dt_pDate.DataBindings.Clear();
this.dt_pDate.DataBindings.Add("Value",dsAll,"Product.PurchaseDate");
this.dt_rDate.DataBindings.Clear();
this.dt_rDate.DataBindings.Add("Value",dsAll,"Product.InputDate"); if(Firsthit)
{
MachineID=this.txt_Serial.Text;
}
MessageBox.Show(this.txt_Voice.Text);
}

if(Firsthit||(TabNum=="1"&&MachineID!=this.txt_Serial.Text))
{
if(MachineID!=this.txt_Serial.Text)
{
MachineID=this.txt_Serial.Text;
}
Sql="select telRecord.*,FaultPheno from telRecord";
Sql+=" inner join FaultPheno on telRecord.pCode=FaultPheno.pCode";
Sql+=" where MachineID='"+MachineID+"'";
MessageBox.Show(Sql);
adpBespeak=new SqlDataAdapter(Sql,CN);
adpBespeak.Fill(dsAll,"Bespeak");

if(Firsthit)
{
dtBespeak=dsAll.Tables["Bespeak"];
AddBespeakDataTableStyle();
}
this.dg_Bespeak.DataSource=null;
this.dg_Bespeak.DataSource=dsAll;
this.dg_Bespeak.DataMember="Bespeak";
CurrencyManager cmBespeak=(CurrencyManager)this.BindingContext[dg_Bespeak.DataSource,dg_Bespeak.DataMember];
((DataView)cmBespeak.List).AllowNew=false;
((DataView)cmBespeak.List).AllowDelete=false;
((DataView)cmBespeak.List).AllowEdit=false; this.cmb_FaultPheno.DataBindings.Clear();
this.cmb_FaultPheno.DataBindings.Add("SelectedValue",dtBespeak,"pCode");
this.txtUseDate.DataBindings.Clear();
this.txtUseDate.Text="";
this.txtUseDate.DataBindings.Add("Text",dsAll,"Bespeak.UseDate");
this.dtp_bTime.DataBindings.Clear();
this.dtp_bTime.DataBindings.Add("Value",dsAll,"Bespeak.BespeakDate");
this.lb_TableNum.DataBindings.Clear();
this.lb_TableNum.Text="";
this.lb_TableNum.DataBindings.Add("",dsAll,"Bespeak.TableNum");

}