ZK framework: I have two Comboboxes; How to clear the 2nd Combobox on selecting a different item on the first Combobox? - combobox

I am new to zk framework and I tried everything but nothing seems to work; I used
#Command
public void clearSelection(#BindingParam("listModel")ListModelList model) {
if (model!=null) {
model.clearSelection();
}
}
and on the 2nd combobox I used:
onChange="#command('clearSelection', listModel=self.model)";
It is clearing the text of the second combobox but the list is not being populated on the second combobox; I want when the value of the first combobox changes then the text that is displayed on the second combobox to be removed
the above function clears the text but the data is not getting binded on the second combobox
i want:
combobox 1 -> (value)
combobox 2 -> (value)
combobox 1 -> (another value)
combobox 2 -> previously displayed data to get clear whilst the data
pertaining to (another value) to be displayed
I tried using #bind instead of #load but cannot comeup with a solution
Thankyou in advance

For those who new to ZK, I recommend using MVC pattern (using Composer) because it's easy to start.
when the value of the first combobox changes then the text that is displayed on the second combobox to be removed
onChange="#command('clearSelection', listModel=self.model)"
This command binding should fulfill this requirement.
but the data is not getting binded on the second combobox
I don't see you bind any model to the 2nd combobox. I suppose there should be 2nd model like:
<combox model="#init(vm.model2)"/>
Besides, you usually don't need to pass a ListModel into a command method like:
public void clearSelection(#BindingParam("listModel")ListModelList model)
Since the ViewModel should already have that ListModel object.

Related

WPF DataGrid checkbox binding

I'm not sure what I'm missing here, but I'm having trouble getting a checkbox to bind to a list properly. The rest of the properties of the list bind just fine, but the checkbox is having issues. Here's what I have:
In the class that serves as the template for each object in the list I have:
Property Process As New CheckBox
In the MainWindow_Loaded Event I have:
Dim ProcessCol As new DataGridCheckBoxColumn
ProcessCol.Header = "P?"
ProcessCol.IsReadOnly = False
...
InputGrid.ItemsSource = InputData 'Which is a list of my Order Allocation objects which contains the checkbox property
...
Dim ProcessBinding As New Binding("Process")
ProcessBinding.Mode = BindingMode.TwoWay
ProcessCol.Binding = ProcessBinding
...
InputGrid.Columns.Add(ProcessCol)
When I try to populate this collection and look at the items I get checkbox = nothing. I'm not sure what I'm missing here... I know I couldn't be too far off...
Edit: I changed the property to "new CheckBox" and now I get an initialzied checkbox object in the list item as "System.Windows.Controls.CheckBox Content: IsChecked:False which in this case should have been true. So maybe a step closer, but still not there.
I found an answer here: WPF: CheckBox in DataGrid
Technically not an answer to my original question, but it works. Rather than a checkbox property in my class I now have a boolean property. The column is still created as a checkbox column. It works.
If a column can be bound to a chebox property of a list I'd still be interested in hearing that, but for me this solution works.

Not add or remove, but edit a combobox item in Silverlight?

So I have this combobox, which ItemsSource is set to a List of objects.
What I want to do after that is change the Display value of one specific Item (the first on the list), because this label does not suit the context in some situations but does in others.
So far I found that you could add an item using the Add method, insert one using the Insert method, and remove one using RemoveAt.
But how do you update one ? I know I could use RemoveAt and Insert afterwards, but it would be a bit labor intensive, plus I would have to recreate the object with all its values...
Any ideas?
Either replace an item in your "List of objects":
myList[0] = new MyObject("Another display text").
For this (and Add, Remove etc) to work, your list would have to be an ObservableCollection<T> or any other that implements INotifyCollectionChanged.
Or modify the item itself:
myList[0].DisplayText = "Another display text";
For this to work, your MyObject class would have to implement INotifyPropertyChanged, you'd have to raise the PropertyChanged event when the DisplayText property is set, and you'd have to set the DisplayMemberPath or the ItemTemplate of your ComboBox correctly.
Take a look at the MVVM pattern for more information.

INotifyPropertyChanged not working as expected

I have a little trouble with INotifyPropertyChanged. I implemented it lots of times, however this case is different. I would like to create the following application:
There are multiple tab containers, which are bound to different ObservableCollections of Entities. Now I would like to show the name of the currently (last) selected Entity. To achieve this, I've created created a DependencyProperty CurrentEntity in the Window class and assign via SelectionChanged on the TabControls the current Entity.
private void SelectionChanged(Object sender, EventArgs e)
{
CurrentEntity = e.NewItems[0] as Entity;
}
The TextBlock which, in the above picture, displays VideoA looks like this:
<TextBlock Text={Binding CurrentEntity.Name}" />
Now whenever I select a new Tab, the Text in the TextBlock changes accordingly. However when I change the the name of an Entity (inside a TextBox in a Tab, which is also bound to the Entity), the text in the TextBlock doesn't change. I have to select another Tab and then change back to the Tab where I changed the Name to see the newly entered name in the TextBlock. Basically, this is my problem, I would like to see the text changing without selecting another Tab first (and yes, I de-focused from the TextBox inside the Tab after entering the new Name).
Has anyone an idea where the problem is?
My "architecture" looks (more or less ;-)) like this:
ObservableCollection just means that the event to update UI is kicked off when the collection changes, you add, remove, re-order, etc.
Altering an the property of an item in an ObservableCollection, such as a string, doesn't not actually cause a UI event.
Does the object you have inside the ObservableCollection implement INotifyPropertyChanged?

WPF: ComboBox only refreshes to binding when never opened

I have a combobox and set the itemssource to a list of strings:
private List<string> list = new List<string>();
...
ComboBox cbo = new ComboBox();
cbo.ItemsSource = list;
The combobox gets filled successful on startup.
But when the list is changed, the combobox doesn't update its items, BUT only when I expanded the items before, else the combobox gets updated...
Also weird: when I trace the count of items of the combobox, the count is the correct updated number, but the displayed items aren't.
Somebody has an idea, what's going on here?
EDIT: See solution in comments to post of Robert
I guess you need to use ObservableCollection instead of List, because ComboBox needs to be notified whenever the collecion changes.
Change List into ObservableCollection.
Use ObservalbeCollection. It has inbuilt mechanism to notify and change in the number of items.

Silverlight MVVM binding seems not to work

Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't understand.
Having a WPF background i don't know what is going on here:
ViewModel has several properties, in which one is called SelectedRecord. This is a get only property and is defined like this:
public Culture SelectedRecord {
get { return culturesView.View.CurrentItem as Culture; } }
As you can see it is gets the current value of a CollectionViewSource (called culturesView). So if i select a Culture, the SelectedRecord (gets a value directly from within the CollectionViewSource) as expected. (Actually there is a datagrid control bound to the CollectionViewSource, hence it is possible to change the selected item)
OK. Now to the View . There are several views which access this ViewModel and in particular there is one which shows the values of the aforementioned property SelectedRecord (let's call it the EditView). To show this EditView there is a button (which has its Command property bound to an ICommand in the ViewModel) which functions (the first time) as expected.
This means:
1st try : i select a record, switch to EditView, outcome: selected record values are shown (as expected!!).
2nd try: switch back to datagrid, select another record, switch to EditView, outcome: the values of the previous shown record are shown again!!! WHY??
First i thought that the SelectedRecord has not the correct value set, but i was mistaken: it HAS the correct value! So it should be shown!?
What am i missing? In WPF this would work!!
Thanks in advance
When CurrentItem value changes, your ViewModel that has SelectedRecord must call RaisePropertyChanged("SelectedRecord") so whatever View is bound to it is notified about the change.

Resources