Hi,
I am having a bit of trouble with some C# code. I can get it working in VB.NET, but can't seem to work out how to get the same code working in C#.
I have a listview which stores information about employees.
Basically
Day, Hours Worked, Hours Off, Absence Reason, Subs, Pay for day.
The listview allows you to select a list and the details from the list are put into various textboxes to allow them to be edited. However, I can't work out how to then re-write those details back to the listview, updating the original record.
I can get it working by looping around each item in the listview, and checking against original data stored then updating but its a messy way of doing it. There must be a way to get the index of the item that is being updated. Then e.g.
updateRecord()
{
listview(recordtoupdate).text = blahblah etc
listview(recordtoupdate).subitem(1).text = blahblah etc
Thanks for any replies,
-
Stuart
3 11607
Where are you storing/ updating the information? This would normally be the place to get the updated info. HTH.
Hello,
Thanks for the reply, all help is appreciated.
Basically I have a file for each employee. The file stores e.g.
name
holiday day entitlement
then the lines for each day they work, including the hours on, hours off, absence type (if any), money subbed etc in a comma delimited list.
The list of employees is read into a combox on a form, I select an employee and it reads in their data and puts each day into a row on the listview. I can click on the listview and that record info gets put into some textboxes.
The problem is updating the original listview with the updated data.
e.g.
I click on row 6 for 01/01/2008 and change the hours on from 8 to 10. I want to then be able to click on update and the data for row 6 will udpate the appopriate subitem. I can then dump the entire listview back to the CSV file by overwriting the original. There is only ever going to be at max a few hundred lines in the file so performance isn't an issue. I can't seem to find a way to know which row number has been updated in the listview.
-
Stuart
Hi
I have solved this.
I used a variable in the class called SelectedRecord. Then when I click on an item in the listview it executes the following code. -
-
if (lvEmployeeDetails.SelectedItems.Count == 0) return;
-
-
ListViewItem selectedItem = lvEmployeeDetails.SelectedItems[0];
-
-
dateDay.Text = selectedItem.Text;
-
txtHoursWorked.Text = selectedItem.SubItems[1].Text;
-
txtHoursOff.Text = selectedItem.SubItems[4].Text;
-
txtSubs.Text = selectedItem.SubItems[2].Text;
-
txtDaysPay.Text = selectedItem.SubItems[5].Text;
-
cmbReasonForAbsence.Text = selectedItem.SubItems[3].Text;
-
-
selectedRecord = lvEmployeeDetails.SelectedItems[0].Index;
-
-
Then to update the record. -
lvEmployeeDetails.Items[selectedRecord].Text = dateDay.Text;
-
lvEmployeeDetails.Items[selectedRecord].SubItems[1].Text = txtHoursWorked.Text;
-
This seems to work, although I am not entirely sure why.
I though selectedItems[0].Index would always return 0 as multi-select is set to false. I guess it doesnt return the index of the group of selected items???
-
Stuart
Sign in to post your reply or Sign up for a free account.
Similar topics
by: billyb |
last post by:
My listview has two columns: Email Address & Email Address Type.
I've figured out how to populate it, but now I'm having trouble figuring out how to properly use the SelectedItems to get at the...
|
by: Graham |
last post by:
Hi everyone
I have a form which contains a ListView control. The code
handles the SelectedIndexChanged event, and changes some
icons on some items in the ListView.
I've found that when I...
|
by: n. Smith |
last post by:
Hi All,
Is it normal that the ListView fires the selectedinexchange event
twice?
I have a LvLoaners list view item that updates 3 text boxes (code
below), when I click on an item. I have set...
|
by: Jonesgj |
last post by:
Hi,
First time I am using this control in lieu of a listbox, and I want to be
able to get values and row positions back ... I seem to be able to get the
first col value back using focusitem, but...
|
by: Steph. |
last post by:
I have a List view displaying data in Detail mode with several columns.
How I can get the column index the user clicked on ? (when user click on an item inside the ListView, not on a column...
|
by: George |
last post by:
Hi all,
How can I get the value stored from the selected item and subitems of a
listview?
Thanks in advance,
George
|
by: forest demon |
last post by:
in a different app, i can grab the index of a ListBox, but when i try
it with a listview with only one column, i'm having issues.
the first line (string) below works as expected.
the second line...
|
by: =?Utf-8?B?TmFjaA==?= |
last post by:
It works on the first selection when I want to get a different selection I get
InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index
The Following is the code
Private...
|
by: =?Utf-8?B?R2lkaQ==?= |
last post by:
Hi,
I'm trying to get the index of a selected Item in ListView.
I'm using the SelectedItemChange Event, but i can't get the item index (like
in listbox for i.e).
How can i get the index?
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
| |