C
Cory Burkhardt
In my application, I am binding controls in a dialog box to a DataRow. The
first time I launch the dialog, it works fine. But if I launch the dialog a
second time and bind it to the same DataRow again, the first control that I
modify will not relinquish input focus to any other control in the client
area of the dialog box. I can't even click the OK or Cancel buttons. Even
if I cancel out of the dialog the first time without making any
modifications, which results in RejectChanges() being called on the row, the
next time I create and show the dialog, it will lock up the input focus. I
dispose the dialog after I am through with it, and the second time I launch
the dialog is with a new instance of it. I can even launch the dialog and
data bind it to different DataRows with no problems. But the first time I
databind it to a DataRow for the second time, the controls lock up. Anyone
know what is causing this strange behavior?
This is my databinding code:
if(gameRow["AwayTeamId"] == DBNull.Value)
gameRow["AwayTeamId"] = -1;
if(gameRow["HomeTeamId"] == DBNull.Value)
gameRow["HomeTeamId"] = -1;
if(gameRow["GameDate"] == DBNull.Value)
gameRow["GameDate"] = defaultDate;
ddlAwayTeam.DataSource = awayRows;
ddlHomeTeam.DataSource = homeRows;
ddlAwayTeam.DisplayMember = ddlHomeTeam.DisplayMember = "Name";
ddlAwayTeam.ValueMember = ddlHomeTeam.ValueMember = "TeamId";
ddlAwayTeam.DataBindings.Add("SelectedValue", gameRow, "AwayTeamId");
ddlHomeTeam.DataBindings.Add("SelectedValue", gameRow, "HomeTeamId");
dtpickDate.DataBindings.Add("Value", gameRow, "GameDate");
first time I launch the dialog, it works fine. But if I launch the dialog a
second time and bind it to the same DataRow again, the first control that I
modify will not relinquish input focus to any other control in the client
area of the dialog box. I can't even click the OK or Cancel buttons. Even
if I cancel out of the dialog the first time without making any
modifications, which results in RejectChanges() being called on the row, the
next time I create and show the dialog, it will lock up the input focus. I
dispose the dialog after I am through with it, and the second time I launch
the dialog is with a new instance of it. I can even launch the dialog and
data bind it to different DataRows with no problems. But the first time I
databind it to a DataRow for the second time, the controls lock up. Anyone
know what is causing this strange behavior?
This is my databinding code:
if(gameRow["AwayTeamId"] == DBNull.Value)
gameRow["AwayTeamId"] = -1;
if(gameRow["HomeTeamId"] == DBNull.Value)
gameRow["HomeTeamId"] = -1;
if(gameRow["GameDate"] == DBNull.Value)
gameRow["GameDate"] = defaultDate;
ddlAwayTeam.DataSource = awayRows;
ddlHomeTeam.DataSource = homeRows;
ddlAwayTeam.DisplayMember = ddlHomeTeam.DisplayMember = "Name";
ddlAwayTeam.ValueMember = ddlHomeTeam.ValueMember = "TeamId";
ddlAwayTeam.DataBindings.Add("SelectedValue", gameRow, "AwayTeamId");
ddlHomeTeam.DataBindings.Add("SelectedValue", gameRow, "HomeTeamId");
dtpickDate.DataBindings.Add("Value", gameRow, "GameDate");