> 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
[quoted text clipped - 27 lines]
> ddlHomeTeam.DataBindings.Add("SelectedValue", gameRow, "HomeTeamId");
> dtpickDate.DataBindings.Add("Value", gameRow, "GameDate");
I bound the two comboboxes to a set of rows that will be used to fill in the
combobox with items. The values filled in include a team name for the
display member, and a team id for the value member. I then binded the
Selected value to a field in another row, a row that represents a game to be
played. In this way, the user can select a team from the combobox, and that
team's id value would get put into the game row. Make sense?
I actually have another dialog that does the same thing, but doesn't have
this kind of double-binding. It binds 6 datetime picker controls to values
in 3 rows (2 controls/values for each row). This is an example of one of
these:
int year = preseasonRow.SeasonEndYear;
if(preseasonRow["StartDate"] == DBNull.Value ||
(DateTime)preseasonRow["StartDate"] == DateTime.MinValue)
preseasonRow["StartDate"] = new DateTime(year-1, 10, 1);
if(preseasonRow["EndDate"] == DBNull.Value ||
(DateTime)preseasonRow["EndDate"] == DateTime.MinValue)
preseasonRow["EndDate"] = new DateTime(year-1, 10, 28);
dtpickBeginPreseason.DataBindings.Add("Value", preseasonRow, "StartDate");
dtpickEndPreseason.DataBindings.Add("Value", preseasonRow, "EndDate");
This dialog has the same control lockup problem when I open it and bind it
to the row for the second time. However, it works fine if I only launch the
dialog once for that specific row.
Cory
> Try commenting out these lines
>
[quoted text clipped - 38 lines]
> > ddlHomeTeam.DataBindings.Add("SelectedValue", gameRow, "HomeTeamId");
> > dtpickDate.DataBindings.Add("Value", gameRow, "GameDate");
Sijin Joseph - 09 Sep 2004 07:22 GMT
Hi Cory,
Are you using ShowDialog() or Show() to show your dialog boxes? More
importantly are you using the same form object when you show the form
the second time.
I think what is happening is that you are reusing the same form object
when you show the form the second time, if this is the case then the
databindings are getting attached twice which is causing the lockup.
Use this to check if a binding already exists
if(dtPickDate.DataBindings["Value"] == null)
{
dtpickDate.DataBindings.Add("Value", gameRow, "GameDate");
}
Similarly you might want to check the databindings for the other
datetime controls as well. You should be ok with setting the datasource
and datamember propertys again.
Also for formatting the DateTime's you might want to take a look at
Binding.Format and Binding.Parse events, they let you format the value
before it is shown in the UI, you could use that convert null or emptty
dates to your requirement and vice-versa.
I still think the SelectedValue databindings are redundant, what you are
trying to do can be done by simply using DataSource and DataMember
properties.
Also take a look at these two good articles on DataBinding, they helped
me a lot.
http://msdn.microsoft.com/vbasic/using/columns/adventures/default.aspx?pull=/lib
rary/en-us/dnadvnet/html/vbnet02252003.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html
/databinding_winforms10_11.asp
Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
> I bound the two comboboxes to a set of rows that will be used to fill in the
> combobox with items. The values filled in include a team name for the
[quoted text clipped - 102 lines]
>>>ddlHomeTeam.DataBindings.Add("SelectedValue", gameRow, "HomeTeamId");
>>>dtpickDate.DataBindings.Add("Value", gameRow, "GameDate");