PDA

View Full Version : [CLOSED] Setting Currently Selected Text as Text for Combobox



hemantpatil
Mar 13, 2013, 5:40 AM
Hi,

Using
Ext.net V2.0
ASp.net with vb

I have gridpanel containing Combobox column in it, i m populating the gridpanel from codebehind. what i want to do is whenever user enters the combobox column, if the cell value is blank then first item in the combobox should get selected, or else if the combobox have some selected text in it the it should appear as text for the cell on focus and user should be able to change it afterwords.

in short the combobox cell in gridpanel should never be empty, either it should show first value in the combobox as cell text or selected text as cell text

for more clarity please refer attached image.

5800

Daniil
Mar 13, 2013, 5:54 AM
Hi @hemantpatil,

Hope this helps.

Example

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

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

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.GridPanel1.GetStore();
store.DataSource = new object[]
{
new object[] { "2" },
new object[] { },
new object[] { "3" }
};
store.DataBind();
}
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>

<script>
var on = function () {

};
</script>

<style>
.myСlass {
}
</style>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:GridPanel ID="GridPanel1" runat="server">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="test" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="Test" DataIndex="test">
<Editor>
<ext:ComboBox ID="ComboBox1" runat="server">
<Items>
<ext:ListItem Text="1" />
<ext:ListItem Text="2" />
<ext:ListItem Text="3" />
</Items>
<SelectedItems>
<ext:ListItem Index="0" />
</SelectedItems>
</ext:ComboBox>
</Editor>
<EditorOptions>
<Listeners>
<StartEdit Handler="if (Ext.isEmpty(value)) {
this.field.select(this.field.getStore().getAt(0));
}

this.field.onTriggerClick();"
Delay="1" />
</Listeners>
</EditorOptions>
</ext:Column>
</Columns>
</ColumnModel>
<Plugins>
<ext:CellEditing runat="server" />
</Plugins>
</ext:GridPanel>
</form>
</body>
</html>

hemantpatil
Mar 13, 2013, 7:00 AM
Hi Daniil,

Thanks for the Reply. it's just what i wanted. Thank you very much.

another thing i want to ask is, as per the example, if the cell value is blank/empty then we use 0 index record from store. this is ok in case of first row in grid where no value is selected in the combobox, but if i add a new row dynamically, then also the value for the column will be empty, but in this scenario i want to set the last selected value in the combobox, or value of previous cell in the same column, as cell text.

how can i do this.

Daniil
Mar 13, 2013, 8:26 AM
I think it is possible to implement in the StartEdit handler.

hemantpatil
Mar 13, 2013, 9:05 AM
Can you please tell me how to get selected value of Combobox in StartEdit handler.

Daniil
Mar 13, 2013, 10:56 AM
Could you, please, provide a sample to test with?