如何从列表框中获取值 [英] how to get a value from list box

查看:131
本文介绍了如何从列表框中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想借助键盘在列表视图控件中上下移动,并且在上下移动时,列表框的相应值应显示在文本框中...
并且列表视图由数据库在加载表单时填充
当我这样做时,然后在移入列表视图中时,列表视图的值就会发生变化,例如数据行视图". br/>
WPF: Selector.SelectionChanged事件 [ ^ ]
WinForms: ListBox.SelectedIndexChanged事件 [ ListView.SelectedIndexChanged事件 [ < html xmlns =" > < =" 服务器" < 标题 > < /title > < 脚本 =" javascript" 类型 文本/javascript " <% TextBox1.ClientID %> ').value = _this.value ; } < /script > < /head > < 正文 > < 表单 =" form1" runat >服务器" > < div > < asp:ListBox ID =" runat 服务器" 宽度 112像素" < asp:ListItem 文本 =" " > Test1 < /asp:ListItem > < asp:ListItem 文本 =" " > Test2 < /asp:ListItem > < asp:ListItem 文本 =" " > Test3 < /asp:ListItem > < asp:ListItem 文本 =" " > Test4 < /asp:ListItem > < asp:ListItem 文本 =" " > Test5 < /asp:ListItem > < /asp:ListBox > < asp:TextBox ID =" runat 服务器" < > < /div > < /form > < /body > < /html >



谢谢,
Imdadhusen


i want to move up and down in a list view control with the help of keyboard and on moving up and down corresponding value of list box should be displayed in a text box...
and the list view is filled by a database on loading the form
when i do that then on moving in list view the value of list view in changed like"Data Row view".

The low tech way to do it:

WPF:
Selector.SelectionChanged event[^]
WinForms: ListBox.SelectedIndexChanged event[^] or ListView.SelectedIndexChanged event[^]

Hook a handler to that event.

In WPF, you should do it with data binding. Bind the ListView''s SelectedIndex to a property of your ItemsSource and give the ItemsSource a CurrentItem property which you can bind the text box to. You can also bind SelectedItem directly to a view model property.


use the event: SelectedIndexChanged
and write

textBox1.Text = listBox1.Text;


or

textBox1.Text = listBox1.SelectedItem.ToString();


You can do Using JavaScript

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
     <script language="javascript" type="text/javascript">
         function SetSelected(_this) {
             document.getElementById('<%TextBox1.ClientID %>').value = _this.value;
         }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
           <asp:ListBox ID="ListBox1" runat="server" Width="112px">
            <asp:ListItem Text="" Value="">Test1</asp:ListItem>
            <asp:ListItem Text="" Value="">Test2</asp:ListItem>
            <asp:ListItem Text="" Value="">Test3</asp:ListItem>
            <asp:ListItem Text="" Value="">Test4</asp:ListItem>
            <asp:ListItem Text="" Value="">Test5</asp:ListItem>
        </asp:ListBox>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>



Thanks,
Imdadhusen


这篇关于如何从列表框中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆