PDA

Click to See Complete Forum and Search --> : ListView Help


Rahils573
Mar 5th, 2004, 10:51 AM
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;

}

Pirate
Mar 5th, 2004, 01:06 PM
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);
}

}
}

Rahils573
Mar 5th, 2004, 01:17 PM
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

Pirate
Mar 5th, 2004, 01:20 PM
You mean like this ?

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;
}

}
}

Rahils573
Mar 5th, 2004, 01:30 PM
I tried to compile it but gives error

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


Pls guide..

Rahil

Pirate
Mar 5th, 2004, 01:33 PM
Try now . sorry it was just synatx error .

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; }
}
}

Rahils573
Mar 5th, 2004, 01:43 PM
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

Pirate
Mar 5th, 2004, 01:53 PM
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 .

Rahils573
Mar 5th, 2004, 02:02 PM
Cannot open the file. With what u open the file????

Pls guide...

R

Pirate
Mar 5th, 2004, 02:09 PM
winrar . and it's C#.NET 2003 proj .

Rahils573
Mar 5th, 2004, 02:11 PM
Can u Zip it and send it.

I do not have winrar

Thanks,

R

Pirate
Mar 5th, 2004, 02:17 PM
You could have downloaded it off the link under my sig . Anyways , it's packed with winzip now .

Rahils573
Mar 5th, 2004, 03:15 PM
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

Pirate
Mar 5th, 2004, 03:21 PM
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 ?

Rahils573
Mar 5th, 2004, 03:25 PM
I am not getting any errors . Just that it is not displaying on the
Text Box.

I am sending my code shortly...

Kapil

Rahils573
Mar 5th, 2004, 03:48 PM
I have attached my application.
Pls guide. Could not figure it out whats happening..

R

Pirate
Mar 5th, 2004, 04:03 PM
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 :


for( int i = 0 ;i< this.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.

Pirate
Mar 5th, 2004, 04:06 PM
Here's your proj back to you if you can't get it work .

Rahils573
Mar 5th, 2004, 04:14 PM
Thanks you very much .Its working now.

Rahil