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 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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |