Show combobox's items as a custom node in tornadofx - kotlin

When use a node to show combobox's items only display the fisrt item I select.
val sspSelected = SimpleStringProperty()
val myItems = FXCollections.observableArrayList("Item 1", "Item 2","Item 3")
combobox<String>(sspSelected){
items = myItems
cellFormat {
graphic = cache{
label(it)
}
}
}
label(sspSelected)
No selected item
First item selected
Third item selected

You are using cache without supplying a cache key, so the graphic node for the cell is calculated from the first value it sees. Simply supply a unique id, in this case the string value as a cache key:
graphic = cache(it) {
label(it)
}

Related

Set input value that has been binded with v-model

I'm creating my own autocomplete feature based on vue.js and materializecss.
https://jsfiddle.net/guanzo/kykubquh/5/
Right now it's working okay, except for a few things.
The normal behavior for an autocomplete is that once you select an item by pressing enter, or clicking, the value of the input becomes your selected item. So if you input "alab", and select the item "Alabama", the value of the input should become "Alabama", and the dropdown list disappears.
The problem is that the input is bound with v-model="query", meaning the value of the input is the value of "query", which is the value of the input.
Trying to change the input value with this.$el.querySelector('input').value = "Alabama" does nothing. My current workaround is to set the value of query to be the value of the selected state.
onSelect(state){
this.selected = state;
this.query = state.name//replace input val
}
A nasty side effect of this is that changing the value of query triggers another search, which causes the dropdown to reappear with the item "Alabama".
How do i change the value of an input that has been bound with v-model?
My attempted workaround is to call this.onBlurInput(); after the user selects an item, which hides the dropdown. However, the dropdown will no longer appear until you explicity refocus the input by clicking outside and back again.
Remove your focus and blur events and add the following line to your queryMatches. You really only want to show options when there is not an exact match.
queryMatches(){
if(this.query.length <= 1){
return [];
}
// check to see if the current value is already in the list
if (this.query === this.selected.name) return [];
console.log(this.query)
var reg = new RegExp(this.query,'gi')
var matches = this.states.filter(state=>{
return reg.test(state.name)
})
console.log(matches)
return matches
}
Here is an updated fiddle.

Is it possible to dynamic set menu items in a wxMenu?

Hi: I have in a wxFrame a menubar with this wxMenus: File|Edit|Personal. During the frame creation the wxMenu Personal has two wxMenuItems (Information and Need Help), which tells the user that must fill the form and help abou how to fill it. After the user fills the form with personal information, the menu is populated with new items: send, clear, check and remove, deleting/removing the previous ones... At this point I manage to trap the event, like this:
Bind (wxEVT_MENU_OPEN, &MyFrame::processMenuPersonal, this);
// the method
void MyFrame::processMenuPersonal (wxMenuEvent& event) {
wxMenu *menu = event.GetMenu ();
wxMenuItem *item = menu->FindItem (IDM_PERSONAL_EMPTY);
if (item) {
// here I want to dynamic add items and remove the current ones
}
}
Any ideas about how to do this?
Yes. Just append as submenu and treat it like any conditional statement. Here is a sample
void MyFrame::processMenuPersonal (wxMenuEvent& event) {
wxMenu *menu = event.GetMenu ();
wxMenu *item = menu->GetMenu(YOUR_MENU_INDEX);
menu->AppendSubMenu(item, wxT("User Items"));
if (YouConditionHere) {
item->Append(wxID_ANY, "Item 1")
item->Append(wxID_ANY, "Item 2")
item->Append(wxID_ANY, "Item 3")
}
}
Note that Items 1,2,3 are the information you want to append after processing your data (in your case deleting old entries)

Exclude Combo box items that held in a datagridview

I have a combo box that is attached to a datasource
cboPies.DataSource = GetPies(txtCustomer.Text)
cboPies.DisplayMember = "PIES_DESCN"
cboPies.ValueMember = "PIES_ID"
I also have a datagridView that has a list of selections that have selected from the combo box.
I am trying to remove the items for the combo box if they have already have the item on the Datagridview or warn the user that it is already selected.
With dgvSelectedPies
For indexDGV As Integer = 0 To .Rows.Count - 1 Step 1
'cboSpecialty.Items.Remove(.Rows(indexDGV).Cells("PIES_DESCN").Value)
cboSpecialty.Items.Remove(.Rows(indexDGV).Cells("PIES_ID").Value)
Next
End With
If you are using a data source then you should not be interacting with the Items collection. The MSDN documentation says:
A data source can be a database, a Web service, or an object that can
later be used to generate data-bound controls. When the DataSource
property is set, the items collection cannot be modified.
Instead, you should be managing your own collection using a BindingList.
Example in C# (sorry):
protected BindingList<Pies> ComboDataSource { get; set; }
...
ComboDataSource = new BindingList<Pies>(GetPies(txtCustomer.Text));
cboPies.DataSource = ComboDataSource;
cboPies.DisplayMember = "PIES_DESCN"
cboPies.ValueMember = "PIES_ID"
...
if(ComboDataSource.Contains(pieInDataGrid))
{
ComboDataSource.Remove(pieInDataGrid);
}

Nested List toolbar

I am creating a nested list and setting the BackText on item tap using "setBackText()". That works fine.
But at the same time, I want the title of the toolbar to be set as well.
The code:
onItemTap : function(nestedList, list, index, node, record, e) {
var partsOfStr = record.get('text').split(';');
val = partsOfStr[2];
currDocument = val;
Ext.getCmp('nestedList').setTitle('HII');
Ext.getCmp('nestedList').setBackText(currDocument);
},
does not seem to be working for me.
Any suggestions?
Thanks in advance.
updateTitleText is by default set to true for nestedlist, so if you are using a data store to set the data for your nestedlist, your title will always be set according to which category of data you are selecting.
So, set
updateTitleText: false
and then try to set the title dynamically like this,
Ext.getCmp('nestedList').setTitle('HII');

Selected ListItem in Datasource not Selected after DataBinding

I'm selecting a ListItem as I add it to a ListItemCollection. Then I use that ListItemCollection as a datasource for a DropDownlist but the Selected List Item is not being selected after databind. Here is an example of the code:
ListItemCollection items = new ListItemCollection();
ListItem item;
item = new ListItem("Option 1", "1");
items.Add(item);
item = new ListItem("Option 2", "2");
item.Selected = true;
items.Add(item);
ddl1.DataSource = items;
ddl1.DataBind();
I'm trying to get this to work so I can return only a list of items, instead of a list of items and the selected value. Is there a way to make the DropDownList select the selected ListItem from the ListItemCollection (or any other type of collection)?
Hmm... this seems like a strange method to take for accomplishing this, you should be able to do something along these lines:
ddl1.Items.Clear();
foreach(ListItem item in items)
{
ddl1.Items.Add(item);
}
Which should solve your selection issue...
I don't think you can set the selected value before you bind to the drop down. I think you have to do it after it has been bound.
Just set the SelectedValue property of your DropDownList :
ddl1.SelectedValue = "Option 2";
Here I'm using a literal string, but it's best to the item.Text value to set it. You can use it before or after the DataBind(), it works either way.