May 05, 2011, 8:21 AM
[CLOSED] GridPanel / Editor / ComboBox : How to show and select the correct Value in a ComboBox in a GridPanel
Hey,
so I have a ComboBox as an Editor in a GridPanel. That ComboBox has its own Store that is populated in code-behind. All ComboBoxes (and thus Stores) has the same values but what value that is Selected should depend on the GridPanels value for that row.
Here is the GridPanel with the ComboBox as Editor:
Code-behind, simplified and stuff:
so I have a ComboBox as an Editor in a GridPanel. That ComboBox has its own Store that is populated in code-behind. All ComboBoxes (and thus Stores) has the same values but what value that is Selected should depend on the GridPanels value for that row.
Here is the GridPanel with the ComboBox as Editor:
<ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
<Store>
<ext:Store ID="Store1" runat="server" >
<Reader>
<ext:ArrayReader>
<Fields>
<ext:RecordField Name="Id"></ext:RecordField>
<ext:RecordField Name="Start" Type="Date"></ext:RecordField>
<ext:RecordField Name="End" Type="String" ></ext:RecordField>
<ext:RecordField Name="ChoosenId" Type="Int" ></ext:RecordField>
</Fields>
</ext:ArrayReader>
</Reader>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column Header="Id" DataIndex="Id"/>
<ext:DateColumn Header="Start" DataIndex="Start" Format="yyyy-MM-dd HH:mm" />
<ext:DateColumn Header="End" DataIndex="End" Format="yyyy-MM-dd HH:mm" />
<ext:Column Header="ChoosenId" DataIndex="ChoosenId">
<Editor>
<ext:ComboBox runat="server" ID="ComboBox1"
DisplayField="Name" ValueField="cId"
TypeAhead = "false" HideTrigger = "false" ForceSelection="false">
<Store>
<ext:Store runat="server" ID="Store2">
<Reader>
<ext:ArrayReader>
<Fields>
<ext:RecordField Name="cId"></ext:RecordField>
<ext:RecordField Name="Name"></ext:RecordField>
</Fields>
</ext:ArrayReader>
</Reader>
</ext:Store>
</Store>
</ext:ComboBox>
</Editor>
</ext:Column>
</Columns>
</ColumnModel>
<Listeners>
<AfterEdit Fn="afterEdit" />
</Listeners>
</ext:GridPanel>
and in the code-behind I populate both the GridPanel and the ComboBox separately. Do note that the "ChoosenId" in the Store1 is one of the Id:s in the Store2 (ComboBox). So I want the item in the ComboBox that has the cId == ChoosenId to be selected.Code-behind, simplified and stuff:
List<object> gridPanel1Object = new List<object>();
foreach (MyGridPanel1Object d in somePlace)
{
gridPanel1Object.Add(new object[]
{
d.Id,
d.Start,
d.End,
d.ChoosenId
});
}
Store1.DataSource = gridPanel1Object;
Store1.DataBind();
// and populate the ComboBox
List<object> myComboBoxItems = new List<object>();
foreach (MyComboBoxItem c in someOtherPlace)
{
myComboBoxItems.Add(new object[]
{
c.Id,
c.Name
});
}
Store2.DataSource = myComboBoxItems ;
Store2.DataBind();
Right now what I see in the GridPanel is the "ChoosenId" as the number, not as the DisplayField in the ComboBox. Here is a picture that might make it clearer:
Last edited by Daniil; May 05, 2011 at 12:23 PM.
Reason: [CLOSED]