DevExpress 多个列表框丢失焦点颜色效果

DevExpress Multiple ListBox LostFocus Color effect

本文关键字:焦点 颜色 列表 DevExpress      更新时间:2023-09-26

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

马上:

  1. 列表框从选择的第一个索引开始(我希望它以没有选择开始)
  2. 跳转到第二个列表框
  3. 时,它会保存第一个列表框索引并应用于第二个列表框。(如何在新选择的列表框中启动新索引?-- 我尝试在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();
}