473,653 Members | 3,000 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_MouseD own(object sender,
System.Windows. Forms.MouseEven tArgs e)
{
// gets currently selected record
li = listView.GetIte mAt(e.X,e.Y);
}

private void listView_Select edIndexChanged( object sender,
System.EventArg s 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.GetIte mAt(e.X,e.Y);' but it never updates the
label. Any suggestions?

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

private void listView1_Click (object sender, System.EventArg s e)

{

Console.WriteLi ne("Item Text: " + listView1.Selec tedItems[0].Text);

Console.WriteLi ne("SubItem 1: " +
listView1.Selec tedItems[0].SubItems[1].Text);

}

Brian :Patterson

"Greg" <st*@kc.rr.co m> 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_MouseD own(object sender,
System.Windows. Forms.MouseEven tArgs e)
{
// gets currently selected record
li = listView.GetIte mAt(e.X,e.Y);
}

private void listView_Select edIndexChanged( object sender,
System.EventArg s 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.GetIte mAt(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.EventArg s e)

{

Console.WriteLi ne("Item Text: " + listView1.Selec tedItems[0].Text);

Console.WriteLi ne("SubItem 1: " +
listView1.Selec tedItems[0].SubItems[1].Text);

}

Brian :Patterson

"Greg" <st*@kc.rr.co m> 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_MouseD own(object sender,
System.Windows. Forms.MouseEven tArgs e)
{
// gets currently selected record
li = listView.GetIte mAt(e.X,e.Y);
}

private void listView_Select edIndexChanged( object sender,
System.EventArg s 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.GetIte mAt(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
1289
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 which downloaded a directory full of files from an ftp server, using an ftplib.FTP object's retrbinary function. http://xoffender.de/Downloads/screenie4.png Now, inside the callback function of the retrbinary call, I was calling the
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 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);
0
2327
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 checkbox, it should either stop the service or start the service depending on each respective service's status. I want the listView to update the status for each service as they are checked. instead all I can seem to do is clear the listView and I...
0
1391
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 user is able to select a folder using a folderBrowser control. I want the paths to all files to be added to the listView control on Form1. My question lies around what thread should perform the item additions. Currently, on Form2, I referenced...
1
4308
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 dropdowns and hitting the 'Search' button. The first column returned is a user name and is added to the panel as a label, the second is a number and is added to the label as the text property of a textbox, so the user can update it. When the...
2
1254
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 approach I had to have a synclock on the listview the whole event handler, after some reading I've understood that updating a control from different threads should use the controls Invoke statement. Should I use it as well? It's not the...
3
1612
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, say 10. 2. The number of total rows is unknown before hand. So if it is larger than 10, the vertical scroll bar should be shown up and let the user view other part of the rows. 3. In my program, I would add those labels one by one, from left to...
4
7606
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 like numbers etc. Anyway, i'm just updating the field properties like lblnumber.Text = variable1; Now the weird thing is that...when i run the app and it cycles through
4
1882
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 part is easy. The part that I am having trouble with is using the code in a form and having a Label's Text property update as a new directory or file is found. What I keep getting is the work being done before it is shown to the user via the...
0
8370
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8283
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8590
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6160
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5620
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.