Linking index of two or more listboxes in VB.NET - vb.net

I'm doing an project and there is an requirment that i haven't come up with the solution yet.
I'm asked to create a result storing system for a long jump competion. I have to create three listboxes to store attempt numbers, results (in metters) and the corresponding points to each results. However, i can only give them one textbox to enter the results, attempt numbers and points must be calculated automatically and each athlete must have 4 results.
There are two things i would like to ask you guys:
If the user has entered something wrong, he/she should be allowed to delete one or all results. And when a result is deleted, all attempt number and point related to that result should be deleted as well. Clearing all is fine with me but only delete one from the list is not really. So how can i solve this problem.
The listbox containing attempt numbers should be in order (1, 2, 3, and 4). I can make the listbox to generate those numbers if the user enters all results in numerical order. HOwever, the problem is that he/she can delete ramdomly selected item. If he/she deleted attempt number 3 for instance, the next result added should have the attempt 3 back instead of attempt 5. And the new added result should move to position between 2 and 4 rather staying at the bottom.
I hope you can understand what i'm trying to say. Sorry about my explaination, English is not my native language.
All of your ansers are appreciated

You could select the item to delete with the listbox, and then remove as Farhan Sabir has said. You could then force the user to re-enter the distance for the attempt they have just deleted as the next value.
If you only have one textbox to enter the results, you could use a label to indicate which attempt they are entering (set it to automatically change to the number of items in the list +1 after entering a ditance). This would Indicate to the user that they have to re-enter a deleted distance straight after they have deleted one. A messagebox could help prompt this as well.
I am not sure how you would change competitor, but you have not mentioned that at all within your question.

something like this ?
ListBox1.Items.Remove(ListBox1.SelectedItem)

I think when you got the index of the selected item (as Farhan Sabir suggestion above), you can delete the item of the other 2 listbox base on that index. Then you may try the listbox1.Items.Insert to insert the item to specific index of the listbox. however, i think you would have to ask the user the input of the attempt number along with the attempt result in order to add it back to the list with right order

Related

Preventing incomplete records from being added to table WITHOUT table change?

So I working on an Access form and ive noticed that when i dont fill out all the fields and close the form, the fields that i did fill out populate into my table as a sort of "incomplete" record which messes up my numbering increment system that i have going. Is there any way of discarding all data entered on form close without making certain fields required in the table properties? I dont want to do this because it gives a message when trying to close and i want to avoid that if possible
The issue of autonumbering incrementing, and that of not wanting to save record with missing fields or values are TWO HUGE different issues.
Try going to a new record, type in a few things, hit esc 2 times (or go to ribbon and use un-do and now exit form.
The record will now be blank and if you exit, then no record is created (however, the auto number will have incremented) So auto number incrementing and saving of records are two VERY DIFFERENT and separate things.
When you start typing into the blank new record on the form - the record becomes "dirty", and a auto number is incremented and assigned to that record.
if you don't want the record to be saved with missing things, then in the forms before update event, you can check for missing fields, or even bad or wrong values, and if you set cancel = true, the record will NOT be saved, nor created.
So, you don't need to set required in the table design. There are often ALL kinds of things you might want to check for. Say you might require first name or last name (one or the other - such things can't be done at table level. So you can have as complex record verification as you want. And as noted, in most cases, you can and would use the forms before update event.
However, preventing a blank record, or a record being saved with missing information? Sure, not problem - a common requirement.
The above has ZERO, but absolute ZERO to do with the autonumber issue.
Access will issue and set the autonumber as SOON as the first key is typed into that form. As noted, you can use undo, and upon exit, NO REOCRD will be created nor saved.
However, the autonumber created will be tossed out - and skipped. The reason for this is for multi-user operation. If two users move to a new blank record, then when one starts typing, the autonumber is assigned. (even if you don't save the record). when the 2nd user starts typing, they also get a autonumber. Now, if both users hit undo (or esc key), then both can exit, and you note that 2 autonumbers will have been skipped. As noted, access works this way so two users can't be assigned the same PK value when adding records.
As a result, autonumbers can NEVER be deemed to not skip. And of course what about deleting records - again, you have gaps.
Autonumbers cannot be used for say invoice numbers, or some kind of external value. Autonumbers can NEVER be assigned ANY more meaning then that of just some "random" like PK value. You can't use those numbers for external business use if such numbers are to say only be sequential without gaps.
If you need a business incrementing number, such as invoice, or job number or whatever? The you need to create your own column, and manage that incrementing in code. (such as assigning that number in the before update event - but as I noted, yo can also CANCEL that before update event for any old reason - including missing fields or even if this is a odd day of the week (any criteria that floats your boat can be used here, and thus when they exit you can prompt them and tell them that the record is incomplete. Or in those special cases, you can even let them exit without a save, but some kind of message probably is better.
So, if you don't want some incomplete record to be saved? Then put whatever you wish into the forms before update event - and set cancel = true (that event has a cancel option built EXACTLY for this purpose). However, that goal of saving, or preventing a record save has VERY LITTLE to do with the issue of not having gaps in the autonumber - that you can't control, and that you cannot prevent. (prevent gaps).
If you need some external business numbering system, you can't use autonumbers. In fact users should never even see autonumbers, and they are for you the developer to build relations between tables.
As such, these internal house keeping auto numbers cannot be used for external business process(s) that require some kind of sequential number without gaps, since that is not their purpose, and worse yet, you can't control or avoid gaps in such numbers anyway.
You can undo, but autonumbers increments means numbers will and are boing to be skipped as a normal operation of the database system.
Since that number is automatic and under control of the database system, and NOT you the developer, the you can only accept how it works and use it - but you can't change the behavour of that auto number. This applies to all and any database systems. In fact later versions of sql server will skip forward by 10,000 when you reboot.
If you don't want to save a record, then put in your code to prevent as such.
If you need a separate issue of some incrementing number for business use? Then add a column to the database and design the increment system to work whatever way you want - but you can't control the built in system, and its not designed with the goal you have here in mind anyway.

My recordset returns only one record even though there are more one record in Microsoft Access

I am creating a form that loads all the information from the Activity_Table into the form. So basically when the user chooses the name of the Company from the Company_Name drop down, and selects the site from the Site_Name combo box, it is supposed to return the values from that site and put them into the form.
Basically one site can appear more than once in the Activity_Table. Yet, whenever the user selects the name of the site, it only returns one record. To make sure of this, I used the .Recordcount method to check how many records that will be retrieved.
So when you check the Activity table, the Site "Accra Mall - 630kva Gen 2 " appears 4 times, yet when you check the recordcount, it only says it appears Once. So because of this, I cannot move either forward or backwards to either the next or previous record.
To make sure that there was nothing wrong with my sql, I run the query in the Query Design and it produced all 4 records of "Accra Mall - 630kva Gen 2".
So there is nothing wrong with the sql statement. Can anyone help me out please?
This is when I choose the name of the site
We can see that it returns only One record here
Yet this is the amount of records it's supposed to produce(This was when I tried the sql code in the query design tab. It returns 4 records, Not 1). So the recordcount is supposed to be 4. Not One.
this is when I tried the sql to in the previous picture.
If I replicated your problem correctly then the answer is to set Data-Entry to no. Check your form properties. Under the data tab there is a data-entry property. set data-entry to no. From microsoft at https://support.microsoft.com/en-us/office/dataentry-property-f4236759-27f6-4fcd-abb0-4aa4acd8fe87 we get an explanation:
You can use the DataEntry property to specify whether a bound form opens to allow data entry only. The Data Entry property doesn't determine whether records can be added; it only determines whether existing records are displayed. Read/write Boolean.

Data Adapter does not update all rows updated

So long story short I have a dgv that gets data from a mysql database and I can make changes to the data in the grid and save back to the table, no problem except this: Changes made by the user on the dgv are not done directly (or manually) on the dgv, rather the user clicks plus or minus buttons and I pragmatically increase or decrease the number in a certain field called Quantity which is actually the only field that can be updated.
Now when I update my adapte command (...da.Update(ds, "salesDet")), the row I changed last does not get updated unless I manually leave that row to another row before pressing the update button. So for instance if I have 3 rows in the dgv and I select row 2 which has a quantity of 1, then I press the plus button, the quantity changes to 2. Then if I immediately press my update button while still on row 2, it will not get updated to my database. It will only work if prior to pressing the update button I leave row 2 to say row 1 or 3. Kind of like because I'm changing the numbers programmatically and not manually, I need to leave the edited row for an "after-update" commitment of the new values to fire? Don't know if I'm making sense but I'm really lost
I have tried dgv.EndEdit(), dgv.RefreshEdit(), dgv.Refresh() before updating but none of that works.
Thanks for your help
Sounds like the current row hasn't been validated yet, so your change has not taken effect. A clumsy hacky way of getting round this might be to set dgv.CurrentRow to nothing at the start of your Update method to force validation.

InfoPath 2010 NaN

I have been trying to update a text field in a form that will automatically generate a new number in a read only state when a user fills out the form. When the user completes the form and selects the submit button, the form will be attached to SharePoint List and the following user will open the form and the number field will be the number +1. I have used 'count(mynumber)' and the field returns 1, but when I close the form and re-open it, the field still displays 1 and never increases. When I use 'count(mynumber) + 1' the field returns 2 and also never updates. Finally, I used 'max(mynumber) +1' and it returns NaN. I have come to the conclusion that there is an array here, but don't know what I need to do, to fix this.
I have informed my manager of 'InfoPath 2010 Cookbook' so hopefully this will help, but I also took a gander as this following link, which was not easy to follow as I believe its for 2007 instead of 2010.
http://claytoncobb.wordpress.com/2009/06/15/auto-numbering-infopath-forms/
I am using SP 2010.
So, here is the simple approach to the simple request:
•Just like in any database, every item in every list and library in SharePoint has a unique ID. This ID is stored in the ID field, which is available for viewing in any list or library. Go to your list, modify the view, and check the box next to the ID field so you can see what I mean. This ID is 100% guaranteed to be unique and is never duplicated.
•Since you already have purchase order numbers, you can't use the IDs by themselves, however, you can use them to drive your auto-generated Service Order numbers
•The easy method for doing this is to utilize your SO field, which is now a Number field, and determine the differential between the next ID in the list and the next Service Order number that needs to be created.
•Then, create a simple workflow in SharePoint Designer 2010 that ONLY runs on the creation of a new item (only runs once per item/form), and set it to add the differential to the current item's ID (Something like Do Calculation: ID + 1200) . Next, use Set Field in Current Item to set your SO field to the variable created by the Do Calculation step
From then on, you will always have a GUARANTEED unique, auto-incremented SO # for each form, and you should make this field read-only inside the form so that users can only view it and not edit it.
--Clayton Cobb

Restricting table row in SQL Reporting 2008

I need to restrict the number of rows in my tablix, and have the left overs go to another page and also be restricted to the same amount and so on....
So my sample dataset has 2 records, to test I added a Grouping Expression as described here http://msdn.microsoft.com/en-us/library/ms157328.aspx
=int((RowNumber(Nothing)-1)/1)
...and set page breaks
this worked successfully, with the first record displayed on its own page and subsequent record displayed on a new page...
Howver when I choose to restrict the no of records to 12 e.g.
=int((RowNumber(Nothing)-1)/12)
I'd expect to see those 2 records displayed on the first page, though i only see one of them...
Any thoughts? Thanks
Thought Id come back and let others know what I had done wrong here, it might help someone.
I was incorreclty applying the expression to the details row... you have to right click the details row then Click Add Group -> Parent Group and apply the expression there.