Click here to Skip to main content
15,913,198 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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".
Posted
Comments
Wayne Gaylard 19-May-11 6:59am    
Are you using wpf or winforms listview ? How are you binding the data to the list view ? your question needs to be more clear, and provide more information.
Sunasara Imdadhusen 19-May-11 7:41am    
Can you provide snippet of code?

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.
 
Share this answer
 
Comments
geetajain 19-May-11 12:07pm    
not working please give me other solution
BobJanova 19-May-11 13:51pm    
Orrrrr you could go read the instructions.
use the event: SelectedIndexChanged
and write
textBox1.Text = listBox1.Text;

or
textBox1.Text = listBox1.SelectedItem.ToString();
 
Share this answer
 
v2
Comments
geetajain 19-May-11 12:05pm    
on loading it shows a error"Invalid argument= value of '-1' is not valid for index"........
Please give me another solution
You can do Using JavaScript

XML
<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
 
Share this answer
 
Comments
BobJanova 19-May-11 10:23am    
Oh, lol, ASPx. I didn't even think of that one. People really need to start tagging their question properly.
geetajain 19-May-11 12:06pm    
i want to do that in windows application.....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900