Results 1 to 19 of 19

Thread: ListView Help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    ListView Help

    Hello Everybody:
    I am trying to select a Row in a ListView and display it on a textbox. However I am not getting the syntax right.Can any body tell me whats wrong?

    Thanks,

    Rahil

    private void cmdSelectItem_Click(object sender,
    System.EventArgs e)
    {
    string text;
    listViewClients.FullRowSelect()= txtSend.Text;

    }

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Code:
    private void listView1_Click(object sender, System.EventArgs e)
    		{						
    
    			for( int i = 0 ;i< this.listView1.Items.Count ;i++)
    			{
    				if (listView1.Items[i].Selected == true)
    				{
    					MessageBox.Show(listView1.SelectedItems[0].Text);						
    				}
    						  
    			}
    		}

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    ListView-Help

    Thanks for the code. But I want to show the selected item in the ListView Control in the textBox (txtSend.text)

    How does the code do that?

    Pls guide...

    Rahil

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    You mean like this ?
    Code:
    private void listView1_Click(object sender, System.EventArgs e)
    		{						
    
    			for( int i = 0 ;i< this.listView1.Items.Count ;i++)
    			{
    				if (listView1.Items[i].Selected == true)
    				{
    txtSend.text(listView1.SelectedItems[0].Text;						
    				}
    						  
    			}
    		}

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    ListView-Help

    I tried to compile it but gives error

    ): 'System.Windows.Forms.Control.Text' denotes a 'property' where a 'method' was expected


    Pls guide..

    Rahil

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Try now . sorry it was just synatx error .
    Code:
    private void listView1_Click(object sender, System.EventArgs e)
    {						
    for( int i = 0 ;i< this.listView1.Items.Count ;i++)
          {
                if (listView1.Items[i].Selected == true)
    	{
    txtSend.text=listView1.SelectedItems[0].Text;			}
          }
    }

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    ListView Help

    The code compiles .However when I select the row on the ListBox
    it does not display on the textBox.. I am selecting the row on the list view control....it should display on the txtSend.Text

    Pls guide...

    Should we use listViewClients.FullRowSelect???

    Pls guide..

    Rahil

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Rahils573
    The code compiles .However when I select the row on the ListBox
    it does not display on the textBox.. I am selecting the row on the list view control....it should display on the txtSend.Text

    Pls guide...

    Should we use listViewClients.FullRowSelect???

    Pls guide..

    Rahil
    I assume you mean Listview not listbox . I created a little example . check it out .
    Attached Files Attached Files

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    ListView-Pls help

    Cannot open the file. With what u open the file????

    Pls guide...

    R

  10. #10
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    winrar . and it's C#.NET 2003 proj .

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    ListView -Help

    Can u Zip it and send it.

    I do not have winrar

    Thanks,

    R

  12. #12
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    You could have downloaded it off the link under my sig . Anyways , it's packed with winzip now .
    Attached Files Attached Files

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    ListView-Pls Help

    The only difference I could finf between yours and my application is that you are adding the values in the Items (aaa,bbb, ccc) Collections.

    Mine is a Client -Server application in which the information is sent by the client to the server.The information is stored in the list view on the server.So the information is added at Run time .

    I do not know whether that is creating any difference.

    Pls guide...

    Rahil

  14. #14
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Adding values at runtime or design time won't make any difference . Both ways would add the item to the collection obj of the listview therefore , has it's own index number .

    Are you getting specific error or anything that make sense ?

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    List View-Pls Help

    I am not getting any errors . Just that it is not displaying on the
    Text Box.

    I am sending my code shortly...

    Kapil

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    ListView Pls Help

    I have attached my application.
    Pls guide. Could not figure it out whats happening..

    R
    Attached Files Attached Files

  17. #17
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Your problem was with attaching the event handler to the listview . To fix this do the following :
    1-Click the listview , then go the properties window , click the yellow icon on the right (events) . Then scroll to Click and doubleclick it . Then copy this code :

    PHP Code:
    for( int i ;ithis.listViewClients.Items.Count ;i++)
    {
        if (
    listViewClients.Items[i].Selected == true)
       {
           
    this.textBox1.Text=listViewClients.SelectedItems[0].Text;
       }

    in the istViewClients_Click generated event . Then you should see your program working fine.

  18. #18
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Here's your proj back to you if you can't get it work .
    Attached Files Attached Files

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    ListView-Pls help

    Thanks you very much .Its working now.

    Rahil

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width