473,503 Members | 1,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating labels from a listview

I'm trying to display record information in labels, I've
got a listview filled with records and when you click on
one of them I want that record's information shown in
several labels. This is how I'm trying to do it:

private void listView_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
// gets currently selected record
li = listView.GetItemAt(e.X,e.Y);
}

private void listView_SelectedIndexChanged(object sender,
System.EventArgs e)
{
if( li != null )
lblNum.Text = li.SubItems[0].Text;
}

With this code li is always null! li is getting set
because my other functions have been using it fine, it
seems that when it tries to access it at this point it's
always null no matter what. I've also tried putting the
line 'lblNum.Text = li.SubItems[0].Text;' right below 'li
= listView.GetItemAt(e.X,e.Y);' but it never updates the
label. Any suggestions?

Thanks,
Greg
Nov 15 '05 #1
2 4455
Do away with your mouse down handler. Access the listviewitems like this:

private void listView1_Click(object sender, System.EventArgs e)

{

Console.WriteLine("Item Text: " + listView1.SelectedItems[0].Text);

Console.WriteLine("SubItem 1: " +
listView1.SelectedItems[0].SubItems[1].Text);

}

Brian :Patterson

"Greg" <st*@kc.rr.com> wrote in message
news:03****************************@phx.gbl...
I'm trying to display record information in labels, I've
got a listview filled with records and when you click on
one of them I want that record's information shown in
several labels. This is how I'm trying to do it:

private void listView_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
// gets currently selected record
li = listView.GetItemAt(e.X,e.Y);
}

private void listView_SelectedIndexChanged(object sender,
System.EventArgs e)
{
if( li != null )
lblNum.Text = li.SubItems[0].Text;
}

With this code li is always null! li is getting set
because my other functions have been using it fine, it
seems that when it tries to access it at this point it's
always null no matter what. I've also tried putting the
line 'lblNum.Text = li.SubItems[0].Text;' right below 'li
= listView.GetItemAt(e.X,e.Y);' but it never updates the
label. Any suggestions?

Thanks,
Greg

Nov 15 '05 #2
Do away with your mouse down handler. Access the listviewitems like this:

private void listView1_Click(object sender, System.EventArgs e)

{

Console.WriteLine("Item Text: " + listView1.SelectedItems[0].Text);

Console.WriteLine("SubItem 1: " +
listView1.SelectedItems[0].SubItems[1].Text);

}

Brian :Patterson

"Greg" <st*@kc.rr.com> wrote in message
news:03****************************@phx.gbl...
I'm trying to display record information in labels, I've
got a listview filled with records and when you click on
one of them I want that record's information shown in
several labels. This is how I'm trying to do it:

private void listView_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
// gets currently selected record
li = listView.GetItemAt(e.X,e.Y);
}

private void listView_SelectedIndexChanged(object sender,
System.EventArgs e)
{
if( li != null )
lblNum.Text = li.SubItems[0].Text;
}

With this code li is always null! li is getting set
because my other functions have been using it fine, it
seems that when it tries to access it at this point it's
always null no matter what. I've also tried putting the
line 'lblNum.Text = li.SubItems[0].Text;' right below 'li
= listView.GetItemAt(e.X,e.Y);' but it never updates the
label. Any suggestions?

Thanks,
Greg

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1285
by: Eric Williams | last post by:
Hello all, I'm working on a little application using PyQt. The main window is just a dialog with 2 progress bars and a few labels. In its original form, the dialog started, then ran a function...
1
913
by: Greg | last post by:
I'm trying to display record information in labels, I've got a listview filled with records and when you click on one of them I want that record's information shown in several labels. This is how...
0
2312
by: willow1480 | last post by:
I am developing a small little Service Control Application. I am using a listview control with checkboxes and getting the list of services I want to control from a text file. When you check a...
0
1381
by: Art Guerra | last post by:
Any tips or information would be most appreciated! Here is my scenario simplified: I have a main application form (Form1) and on that form is a listView control. On a separate form (Form2), the...
1
4280
by: sekisho | last post by:
I'm dynamically adding a column of labels and a column of text boxes to a panel on a webform, based on data returned from an SQL query, which the user builds by selecting options from a few...
2
1248
by: Kejpa | last post by:
Hi, I've got a number of objects that each have it's own thread. When the value changes I raise an event. Now, I want to handle the event in a form and show the value in a listview. With my first...
3
1597
by: Gary | last post by:
I have a bunch of labels, and want to put in some container, which should be: 1. The number of labels for each column is fixed, say 16/row. And the number of currently displaying rows is fixed,...
4
7601
by: directory | last post by:
hey guys, I've got a weird one for ya....i have a form which takes user input in the form of textbox's etc. It then grabs some details from a file and updates some of the labels with some info...
4
1876
by: Edwin Velez | last post by:
http://msdn.microsoft.com/en-us/library/806sc8c5.aspx The URL above gives sample code for use within a Console Application. What I would like to do is use this code within a Windows Form. That...
0
7188
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7063
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6970
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7441
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3146
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.