Dim columns = Text.Split(","c)
For Each line As String In columns
Call hours()
Dim its As ListView.SelectedListViewItemCollection = lvwData.SelectedItems
its(0).SubItems(4).Text = txtAvail.Text
Next
Auto-Update on Form Load
Page 1 of 14 Replies - 1120 Views - Last Post: 28 March 2012 - 05:15 AM
#1
Auto-Update on Form Load
Posted 26 March 2012 - 06:03 PM
I'm creating part of a program which calculates vacation hours multiplied by accrual rate. As of right now all parts of the form are functioning and saving/retrieving data from a csv text file. My problem is that I'd like to bring the process out of a button.click event and into Form_Load. Currently when I click a listview item (lvwData.SelectedItems) it populates a textbox (txtAvail), then recalculates the textbox value based off my formula (hours) and updates the listview's 4th column item. To update each column daily, I currently have to click each row, then my button, then move onto the next item. I'm looking for a way to grab the 4th column, recalculate it and update the listview without having to select each row. Any suggestions, code sample, or a URL pointing me in the right direction would be helpful. Thanks
Replies To: Auto-Update on Form Load
#2
Re: Auto-Update on Form Load
Posted 27 March 2012 - 03:06 AM
than instead selected items collection loop through items collection.
I don't know is this right code for you,if i understand you are doing some calculations depending on selected items. Pleas post your code 'hours()' that we can see what is really happening.
Dim columns = Text.Split(","c)
For i as Integer = 0 to ListView.Items.Count - 1
ListView.Items(i).SubItems(4).Text = txtAvail.Text
Next
I don't know is this right code for you,if i understand you are doing some calculations depending on selected items. Pleas post your code 'hours()' that we can see what is really happening.
This post has been edited by sela007: 27 March 2012 - 03:23 AM
#3
Re: Auto-Update on Form Load
Posted 27 March 2012 - 11:16 AM
Thanks for your help on this. The issue I'm having is being able to calculate by looking into the 4th subitem of each row of either the text file or listview without referencing the txtAvail textbox. Right now the listview populates everything in the csv file on form load, but I'd like it to recalculate the 4th subitem from each row as well, then refresh that to the listview automatically. Your code works wonderfully, but still requires that something be shown in the txtAvail box. I've added the project, a sample text file (HRVC.hrf), and a screenshot. I have a button programmed to add the data to the listview, which calculates everything correctly. But is still a manual click the listview row/click the add button process. I've set Option Strict On, and I'm a glutton for If/Then statements.
If you or anyone has an idea how to change txtAvail to my hours call, that'd be great.
If you or anyone has an idea how to change txtAvail to my hours call, that'd be great.
Dim columns = Text.Split(","c)
For i as Integer = 0 to ListView.Items.Count - 1
ListView.Items(i).SubItems(4).Text = 'Call hours()
Next
Attached File(s)
-
HRVC.zip (301.55K)
Number of downloads: 29
#4
Re: Auto-Update on Form Load
Posted 27 March 2012 - 06:42 PM
Let me try to ask the question in an easier way. Using a listview and putting code into the Form Load, how would I correct the code below? The code is currently creating an error "Expression is a value and therefore cannot be a target of an assignment."
Dim TempNode As ListViewItem
For Each TempNode In lvwData.Items
TempNode.SubItems.Item(4).ToString = Date.Now
Next
#5
Re: Auto-Update on Form Load
Posted 28 March 2012 - 05:15 AM
Function "ToString" is used when you want to convert some variable,or type to string. In case you have one integer variable and one string variable, and you want to assign integer to string, then you will use 'ToString'
in your code change line number 3
You can see this will work even 'TempNode.SubItems.Item(4).Text' is STRING and 'Date.Now' is DATE. it's because VB is doing conversions automatically.
If you convert to string it will be the same:
Dim int As Integer = 3 Dim str as String str = int.ToString()
in your code change line number 3
TempNode.SubItems.Item(4).Text = Date.Now
You can see this will work even 'TempNode.SubItems.Item(4).Text' is STRING and 'Date.Now' is DATE. it's because VB is doing conversions automatically.
If you convert to string it will be the same:
TempNode.SubItems.Item(4).Text = Date.Now.ToString()
This post has been edited by sela007: 28 March 2012 - 05:19 AM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|