View Full Version : MultiCombo that Remember Selection through page

Sep 20, 2011, 5:09 PM

I resolve what i write in title my self.

I post here my solution because i think could be implemented better by you.

Create a multicombo dynamically (in page init)
Create and associate a store to multicombo (in page init)

In my case i choose for remote page and sort for scalability reason but this is not important, also create in codebehind not is a need.

Dim ComboBox as New Ext.Net.MultiCombo
ComboBox.selectionMode = Ext.Net.MultiSelectMode.All
ComboBox.id = "MyID"
ComboBox.ID = FormField.@ID
ComboBox.FieldLabel = "MyCombo"
ComboBox.Triggers.Add(New Ext.Net.FieldTrigger With {.Icon = TriggerIcon.Clear, .HideTrigger = True})
ComboBox.Listeners.TriggerClick.Handler = "if (index == 0) { this.clearValue(); this.triggers[0].hide(); }"
ComboBox.Listeners.Select.Handler = "this.triggers[0].show();"

Dim Store As New Ext.Net.Store
Store.RemotePaging = True
Store.RemoteSort = True
Store.BaseParams.Add(New Ext.Net.Parameter With {.Name = "start", .Value = "0", .Mode = ParameterMode.Raw})
Store.BaseParams.Add(New Ext.Net.Parameter With {.Name = "limit", .Value = "10", .Mode = ParameterMode.Raw})
Store.Proxy.Add(New Ext.Net.PageProxy)
Store.AutoLoad = False
AddHandler Store.RefreshData, AddressOf MultiBoxStore_RefreshData

Dim StoreReader As New JsonReader
StoreReader.Fields.Add(New Ext.Net.RecordField("Display", RecordFieldType.String))
StoreReader.Fields.Add(New Ext.Net.RecordField("Value", RecordFieldType.String))

ComboBox.DisplayField = "Display"
ComboBox.ValueField = "Value"
ComboBox.PageSize = Integer.Parse(FormField.@PageSize)


After try about two day a way to save/remember selection when i change page for scroll into data and nothing goes (viewstate,session,js script,etc.) i realize that there some limitation by control design to preselect items; what i understand is that if i can reinsert my previous selected item into store dataitems all goes right without complicated solution.

Here is what i do in RefreshData event

Private Sub MultiBoxStore_RefreshData(sender As Ext.Net.Store, e As Ext.Net.StoreRefreshDataEventArgs)
Dim DataSource As New List(Of MyEntityClass)

If TypeOf sender.Parent Is Ext.Net.MultiCombo Then
For Each Item In CType(sender.Parent, Ext.Net.MultiCombo).SelectedItems
DataSource.Add(New MyEntityClass With {.Display = Item.Text, .Value = Item.Value})
End If

Dim OnlySelectedValues = (From Record In DataSource Select Record.Value Distinct).ToList
Dim MyDataBaseDataPaged = (From Record In DataContext.MyEntityClass Skip e.Start Take e.Limit).ToList
Dim ItemsToAdd = From Record In MyDataBaseDataPaged Where Not OnlySelectedValues.Contains(Record.Value) 'For not repeat twice same item

'Is a separator for userfriendly look, the "," in value help me to render unselectable this item
DataSource.Add(New MyEntityClass With {.Value = ",", .Display = "<i>-- Items already selected --</i>"})


sender.DataSource = DataSource

e.Total = DataContext.MyEntityClass.Count

End Sub

How you can see is a very simple solution for a complex problem, what i ask to you is to give us this possibility by control design and a new listitem type for render separator without create complex template layout

For any question i'm here for you

Sep 21, 2011, 4:50 PM

Thanks for sharing.

Do you mind to move the thread to the Examples and Extras forum?