DevExpress Multiple ListBox LostFocus 颜色效果

DevExpress Multiple ListBox LostFocus Color effect

所以我有 2 个列表框,我想将之前选择的每个列表框索引项都变成绿色。

现在:

  1. 列表框从选择的第一个索引开始(我希望它从没有选择开始)
  2. 跳转到第二个列表框时,它会保存第一个列表框索引并应用于第二个列表框。 (如何在新选择的列表框上启动新索引? -- 我尝试在 GotFocus 上重置索引,但它仍然不起作用)

此处显示的示例:http://screencast.com/t/tFsYNJul

这是javascript:

var previousIndex = -1;
function OnInit(s, e) {
    previousIndex = s.GetSelectedIndex();
}

function OnSelectedIndexChanged(s, e) {
    if (previousIndex > -1) {
        s.GetItemRow(previousIndex).style.backgroundColor = 'green';
        previousIndex = s.GetSelectedIndex();
    }
}

标记:

<form id="form1" runat="server">

    <dx:ASPxListBox ID="ListBox1" runat="server" Width="100px" Height="150px">

        <Items>
            <dx:ListEditItem Text="1" />
            <dx:ListEditItem Text="2" />
            <dx:ListEditItem Text="3" />
            <dx:ListEditItem Text="4" />
            <dx:ListEditItem Text="5" />
        </Items>
        <ItemStyle SelectedStyle-ForeColor="Black" SelectedStyle-BackColor="Yellow" />

        <ClientSideEvents Init="OnInit" LostFocus="function (s,e) { s.UnselectAll();  }" SelectedIndexChanged="OnSelectedIndexChanged" />
    </dx:ASPxListBox>

            <dx:ASPxListBox ID="ASPxListBox1" runat="server" Width="100px" Height="150px">

        <Items>
            <dx:ListEditItem Text="1" />
            <dx:ListEditItem Text="2" />
            <dx:ListEditItem Text="3" />
            <dx:ListEditItem Text="4" />
            <dx:ListEditItem Text="5" />
        </Items>
        <ItemStyle SelectedStyle-ForeColor="Black" SelectedStyle-BackColor="Yellow" />

        <ClientSideEvents Init="OnInit" LostFocus="function (s,e) { s.UnselectAll();  }"  SelectedIndexChanged="OnSelectedIndexChanged" />
    </dx:ASPxListBox>
</form>

这将正确处理所需的内容:

function OnInit(s, e) {
    s.cpPreviousIndex = s.GetSelectedIndex();
}

function OnSelectedIndexChanged(s, e) {
    if (s.cpPreviousIndex > -1) {
        s.GetItemRow(s.cpPreviousIndex).style.backgroundColor = '#C0E0CE';
    }
    s.cpPreviousIndex = s.GetSelectedIndex();
}