PDA

View Full Version : [CLOSED] ComboBox ForceSelection with Store Data vs DataSource



tylert
Oct 31, 2014, 3:53 PM
UPDATE: I found this issue has already been addressed on the forum, please see my reply below.

I'm having an issue with a ComboBox I'm creating from the code behind, where ForceSelection is set to true. If I load the ComboBox's store via DataSource then the value does not get set from the code behind on the initial load. However, if I use Data instead of DataSource, then it works. I want to use DataSource because it only serializes the fields that are in the store's model.

The problem seems to come down to the fact that using DataSource loads the data via a MemoryProxy, while using Data sets the Store's data directly.

Below is a simplified example. The combobox should select the single item it has upon loading, but it doesn't. If you change "DataSource" to "Data" then it will work like I'm expecting.




<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
ComboBox TestCombo = new ComboBox
{
ID = "ComboBox1",
ValueField = "Field1",
DisplayField = "Field2",
ForceSelection = true
};

TestCombo.Store.Add(new Store
{
Model = {
new Model {
Fields = {
new ModelField("Field1"),
new ModelField("Field2")}
}
}
});

TestCombo.GetStore().DataSource = new object[] { new { Field1 = "asdf", Field2 = "qwerty" } };
TestCombo.GetStore().DataBind();
TestCombo.SetValue("asdf");

ComboContainer.Items.Add(TestCombo);
}
</script>

<!DOCTYPE html>
<html>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:Panel ID="ComboContainer" runat="server"></ext:Panel>
</form>
</body>
</html>

tylert
Oct 31, 2014, 4:10 PM
Just found this issue has already been logged here:

http://forums.ext.net/showthread.php?23188-OPEN-136-ComboBox-ForceSelection-problem

One of the workarounds mentioned here will work for me. Feel free to close this one.