473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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 4445
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.