cyimxtck
asked on
WPF window 1 trying to reload window 2's drop down list
In what seems so simple, I cannot get the first window to update the drop down list from a second window.
So a products window opens and all is good. A click event opens another window to add a product should it not exist already. Now in that second window I successfully add the product that is missing so I can select that value in the drop down list in window 1.
In window 2 I have:
var ProductsWindow = new Products();
ProductsWindow.PopulateDro pDown();
When I step through the code it goes and fires everything as would be imagined.
When I click the drop down in window 1 it still doesn't have the new value. If I close and reload window 1 the value is there.
Is there like a refresh or something in WPF 4.0 that I am missing and if so how can I instantiate this method?
Please help! :)
Thanks in advance,
B
So a products window opens and all is good. A click event opens another window to add a product should it not exist already. Now in that second window I successfully add the product that is missing so I can select that value in the drop down list in window 1.
In window 2 I have:
var ProductsWindow = new Products();
ProductsWindow.PopulateDro
When I step through the code it goes and fires everything as would be imagined.
When I click the drop down in window 1 it still doesn't have the new value. If I close and reload window 1 the value is there.
Is there like a refresh or something in WPF 4.0 that I am missing and if so how can I instantiate this method?
Please help! :)
Thanks in advance,
B
Hope you are used ObservableCollection<T> to bind to drop down. Adding/Removing an item automatically Binds to the control.
ASKER
I am looking at how to do this now and hope that it works.
ASKER
I am having problems trying to create the ObservableCollection and use it successfully.
There are thousands of pages on the web with examples but this doesn't give me the insight I am trying to get.
I have tried many things:
private ObservableCollection<Produ cts> products;
public ObservableCollection<Produ cts> Product
{
get { return products; }
set { products = value;
OnPropertyChanged(new PropertyChangedEventArgs(" Products") );
}
}
public event PropertyChangedEventHandle r PropertyChanged;
public void OnPropertyChanged(Property ChangedEve ntArgs e)
{
if (PropertyChanged != null)
PropertyChanged(this, e);
}
and nothing is working?
I have a dataset that I need to make the collection and when it changes, have the drop down list contian the new value. It can only ever be a new value and only one value could appear at a time as new...
Any thoughts?
There are thousands of pages on the web with examples but this doesn't give me the insight I am trying to get.
I have tried many things:
private ObservableCollection<Produ
public ObservableCollection<Produ
{
get { return products; }
set { products = value;
OnPropertyChanged(new PropertyChangedEventArgs("
}
}
public event PropertyChangedEventHandle
public void OnPropertyChanged(Property
{
if (PropertyChanged != null)
PropertyChanged(this, e);
}
and nothing is working?
I have a dataset that I need to make the collection and when it changes, have the drop down list contian the new value. It can only ever be a new value and only one value could appear at a time as new...
Any thoughts?
ASKER
Tried this and it doesn't work either....
In the child window button click event: ProductsWindow.Handler();
In the parent window with the drop down:
private ObservableCollection<DataS et> productcollection;
public void Handler()
{
productcollection = new ObservableCollection<DataS et>();
productcollection.Collecti onChanged += HandleChange;
}
public void HandleChange(object sender, NotifyCollectionChangedEve ntArgs e)
{
DataSet DS = DatabaseFunction.ExecuteSt oredProcDS (conn, OracleObjects.SelectExchan ge);
foreach (var x in e.NewItems)
{
rcboCommodityExchange.Item s.Add(prod uctcollect ion.ToStri ng());
}
}
In the child window button click event: ProductsWindow.Handler();
In the parent window with the drop down:
private ObservableCollection<DataS
public void Handler()
{
productcollection = new ObservableCollection<DataS
productcollection.Collecti
}
public void HandleChange(object sender, NotifyCollectionChangedEve
{
DataSet DS = DatabaseFunction.ExecuteSt
foreach (var x in e.NewItems)
{
rcboCommodityExchange.Item
}
}
Silly Question, did you bind the collection to the drop down control ? can we see the whole source code please
ASKER
Here is where it gets populated originally in the main window:
public void ProductsOpen()
{
this.Show();
PopulateDropDowns();
}
public void PopulateDropDowns()
{
PopulateExchanges();
}
public void PopulateExchanges()
{
DataSet DS = DatabaseFunction.ExecuteSt oredProcDS (conn, OracleObjects.SelectExchan ge);
try
{
foreach (DataRow DR in DS.Tables[0].Rows)
{
rcboCommodityExchange.Item s.Add(DR[0 ].ToString ());
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
DS.Dispose();
}
}
Here are the two new pieces I have tried:
private ObservableCollection<DataS et> productcollection;
public void Handler()
{
productcollection = new ObservableCollection<DataS et>();
productcollection.Collecti onChanged += HandleChange;
}
public void HandleChange(object sender, NotifyCollectionChangedEve ntArgs e)
{
DataSet DS = DatabaseFunction.ExecuteSt oredProcDS (conn, OracleObjects.SelectExchan ge);
foreach (var x in e.NewItems)
{
rcboCommodityExchange.Item s.Add(prod uctcollect ion.ToStri ng());
}
foreach (var y in e.OldItems)
{
//do something
}
if (e.Action == NotifyCollectionChangedAct ion.Move)
{
//do something
}
}
private ObservableCollection<Produ cts> products;
public ObservableCollection<Produ cts> Product
{
get { return products; }
set { products = value;
OnPropertyChanged(new PropertyChangedEventArgs(" Products") );
}
}
public event PropertyChangedEventHandle r PropertyChanged;
public void OnPropertyChanged(Property ChangedEve ntArgs e)
{
if (PropertyChanged != null)
PropertyChanged(this, e);
}
private void PopulateProductTypes()
{
DataSet DS = DatabaseFunction.ExecuteSt oredProcDS (conn, OracleObjects.SelectDistin ctProductT ype);
try
{
foreach (DataRow DR in DS.Tables[0].Rows)
{
rcboCommodityMapping.Items .Add(DR[0] .ToString( ));
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
DS.Dispose();
}
}
Here is the child window and its insert:
private void btnSubmit_Click(object sender, RoutedEventArgs e)
{
Cleanup();
var ProductsWindow = new Products();
try
{
if (tbxExchange.Text.Length > 0)
{
if (ExistingExchanges() == false)
{
StoredProcParameter[] oPL = ExchangeName();
DatabaseFunction.ExecuteSt oredProcNo nQuery(con n, OracleObjects.InsertExchan ge, ref oPL);
ProductsWindow.Handler();
tbxStatus.Text = "Exchange entered successfully.";
}
else
{
tbxStatus.Text = "That Exchange already exists.";
}
}
else
{
tbxStatus.Text = "Please enter an Exchange.";
}
}
catch (OracleException OE)
{
tbxStatus.Text = OE.Errors.ToString();
}
}
***** Note: I walk through this code and cannot get it to hit the HandleChange method in the parent window even though I have it called out in the Handler method as:
productcollection.Collecti onChanged += HandleChange;
public void Handler()
{
productcollection = new ObservableCollection<DataS et>();
productcollection.Collecti onChanged += HandleChange;
}
public void HandleChange(object sender, NotifyCollectionChangedEve ntArgs e)
If I am missing something trivial please forgive me as I have tweaked this code 100 times at least.
Thanks,
B
public void ProductsOpen()
{
this.Show();
PopulateDropDowns();
}
public void PopulateDropDowns()
{
PopulateExchanges();
}
public void PopulateExchanges()
{
DataSet DS = DatabaseFunction.ExecuteSt
try
{
foreach (DataRow DR in DS.Tables[0].Rows)
{
rcboCommodityExchange.Item
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
DS.Dispose();
}
}
Here are the two new pieces I have tried:
private ObservableCollection<DataS
public void Handler()
{
productcollection = new ObservableCollection<DataS
productcollection.Collecti
}
public void HandleChange(object sender, NotifyCollectionChangedEve
{
DataSet DS = DatabaseFunction.ExecuteSt
foreach (var x in e.NewItems)
{
rcboCommodityExchange.Item
}
foreach (var y in e.OldItems)
{
//do something
}
if (e.Action == NotifyCollectionChangedAct
{
//do something
}
}
private ObservableCollection<Produ
public ObservableCollection<Produ
{
get { return products; }
set { products = value;
OnPropertyChanged(new PropertyChangedEventArgs("
}
}
public event PropertyChangedEventHandle
public void OnPropertyChanged(Property
{
if (PropertyChanged != null)
PropertyChanged(this, e);
}
private void PopulateProductTypes()
{
DataSet DS = DatabaseFunction.ExecuteSt
try
{
foreach (DataRow DR in DS.Tables[0].Rows)
{
rcboCommodityMapping.Items
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
DS.Dispose();
}
}
Here is the child window and its insert:
private void btnSubmit_Click(object sender, RoutedEventArgs e)
{
Cleanup();
var ProductsWindow = new Products();
try
{
if (tbxExchange.Text.Length > 0)
{
if (ExistingExchanges() == false)
{
StoredProcParameter[] oPL = ExchangeName();
DatabaseFunction.ExecuteSt
ProductsWindow.Handler();
tbxStatus.Text = "Exchange entered successfully.";
}
else
{
tbxStatus.Text = "That Exchange already exists.";
}
}
else
{
tbxStatus.Text = "Please enter an Exchange.";
}
}
catch (OracleException OE)
{
tbxStatus.Text = OE.Errors.ToString();
}
}
***** Note: I walk through this code and cannot get it to hit the HandleChange method in the parent window even though I have it called out in the Handler method as:
productcollection.Collecti
public void Handler()
{
productcollection = new ObservableCollection<DataS
productcollection.Collecti
}
public void HandleChange(object sender, NotifyCollectionChangedEve
If I am missing something trivial please forgive me as I have tweaked this code 100 times at least.
Thanks,
B
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.