Delete function first or last record - vb.net

My main menu is where all records are displayed. The user can navigate between records by a list table which has all the records.
When i use the this code to delete a displayed record, allways the first record gets deleted.
BindingContext(JobsDBDataSet, "T_Jobs")
.RemoveAt(BindingContext(JobsDBDataSet, "T_Jobs").Position)
Ive added an extra line in which the position should match the ID of the record.
BindingContext(JobsDBDataSet, "T_Jobs").Position = Job_IDTextBox
BindingContext(JobsDBDataSet, "T_Jobs")
.RemoveAt(BindingContext(JobsDBDataSet, "T_Jobs").Position)
NOTE: Job_IDTextBox is directly connected to the column in the database (I dragged it from the datasource menu into the form in details form)
My goal is so that i can delete the job that has been selected (and displayed) from the list box (with all records in it)

Right so ive changed my code to
BindingContext(JobsDBDataSet, "T_Jobs").Position = Convert.ToInt32(Job_IDTextBox.Text)
BindingContext(JobsDBDataSet, "T_Jobs").RemoveAt(BindingContext(JobsDBDataSet, "T_Jobs").Position)
And the same thing still happens: last job is deleted and not the selected one (from the listbox). I have a feeling its a problem regard the listbox, and maybe I'd firstly have to tell the program to change its pointer to the job ive chosen from the list box but i have no idea how to do this - and this is just an assumption.

Related

When the user clicks a text box on my form, I need to assign an ID to the current record if there isn't one already

I have a form, frmEvent, for editing and creating records. Each record represents an Event. I have a pop-up form that displays the many-to-many relationships that associate one or more Persons to the current Event. This pop-up form is opened when the user clicks a text box on frmEvent.
The pop-up form displays all of the records in tblEventPersons where EventID = the ID of the Event record that is currently open. This normally works great. However, when my form is used to create a new Event record, Access does not assign an ID for the new Event record until at least one field has been changed. If a user creates a new Event record and tries to immediately open the frmEventPersons form, they get an error because the new Event record does not yet have an ID assigned.
I'm sure there's a very simple solution to this, but my searches have not yielded anything useful.
Well it is assumed that the main form has a record, and has some data and has a "ID" as you well asked.
However, if the form is moved to a new record, and you want to launch that next form that requires and needs the current forms ID that as you WELL note has not yet been generated?
Well, keep in mind that you current form WILL IN FACT generate the ID (assuming a auto number PK id column) if the current record has been "dirtied". We thus assume that the current record had SOME data editing. If it has NO EDITING done, then it actauly turns out is a bit of a trick to get Access force feed and generate that ID.
About the MOST easy way?
Dirty some field/column in the current form.
eg:
if isnull(me!ID) then
' this record does not yet have the PK id
' dirty some bound control.
me.MyEditDate = date()
end if
me.Dirty = false ' this will force a recrod save - gereate the "ID" you want.
docmd.Open "frmDetails",,,"FKColumn = " & me!id

Datagridview.Rows(#).Selected not updating CurrentRow.Index

VB.Net 4.6.1
Windows Forms application
I have a bound datagridview that I'm trying to sort and select. The data loads fine and I can click the headers (with some code) and the sorting works well. I'm working on reselecting a record after the sort is complete and I'm running into some trouble.
Assume that I have a datagridview with 20 records in it. On the form I also have a button that runs the following:
MessageBox.Show(MyDataGridView.CurrentRow.Index.ToString)
I also have a Sub that handles MyDataGridView.Sorted and in it I have one test line as follows:
MyDataGridView.Rows(2).Selected = True
After the data loads I click on the 11th record (selectionmode fullrowselect) and then I click the button. Box pops up and says "10" (0 based index). I click one of my column headers, the data sorts and the highlight bar jumps up to the 3rd record (index 2). However when I hit my currentrow.index button it still says 10. Additionally if I hit the down arrow key the selection bar jumps down to the 11th (index 10) record in the list.
It seems that using "Selected" doesn't update the currentrow.index value and since it is read-only I can't force it. Can anyone educate me on what's going on because, as it is, my users would be confused if the arrow up and down keys didn't work properly after a sort.
Thank you!
"Current" and "selected" do not mean the same thing. How could they, when multiple rows can be selected but there can only be one current row? The current row is the row that currently contains the caret and a selected row is one that is highlighted. If you want the row at index 2 to be the current row then you need to make a cell in that row the current cell, i.e. assign a cell in that row to the CurrentCell property.

Editing SWT Table cell. Changed value jumps back immediately to old value as soon as I leave cell. Why?

I have a Dialog and there is a Table (Tableviewer) inside it.
tableViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI);
Certain columns of my table are editable. I click on the cell, I edit the value, I leave the cell and the edited value immediately reverts back to the old one.
What should I configure/set in table/tablehelper to make the edited values last longer than the time I spend in the cell?
EDIT!-----------------------------
We have a Helper class that is responsible for creating CellEditingSupport like this:
`
if ("w".equalsIgnoreCase(hd_bean_mode)) {
CellEditingSupport editingSupport = new CellEditingSupport(viewer,pds[i]);
col.setEditingSupport(editingSupport);
}`
This class itself is quite complex and does a lot of magic through reflexion, etc... The funny thing however is that other tables use this very same Helper class, seemingly with the same configuration and they work!
One more thing: I am conviced that the columns in my table get the Editingsupport. I know it because of the debugger and because the cells are editable. The only problem is that those edits do not last long.

Use command button to open selected record on a form without filtering?

I have a continuous form which displays a small amount of data from each record in my table ProjectT (i.e. project name, status) and a command button in the footer which I would like to open the selected record in its expanded single form (where all of the relevant info is displayed).
At first I set this button up using Access's wizard, but realized that Access opens a selected record by filtering the data on the form. The problem with this is that once the expanded form is opened, I want a user to be able to move to other records without having to select to unfilter the results. If I change the button on my continuous form to simply open the expanded single form, is there code I can run to make the form open to the selected record without putting a filter on?
Initially I thought to set the expanded form's (named ProjectF) default value to Forms!ProjectListF!ProjectID (where ProjectListF is the continuous form and ProjectID is the autonumber primary key for ProjectT), but this was not successful, I think because there is more than one ProjectID displayed on ProjectListF.
Another thing to consider is that I have another button on my Main Menu form which opens the ProjectF form in data entry mode to prevent the user inadvertently changing/deleting an existing record when they are trying to add a new one; I have no idea if this might be important when trying to find a solution to my issue.
I'm open to any suggestion--I have an okay handle on SQL, and have delved into a little VBA but am completely self taught. Any ideas? Thanks!
You can open the detailed form with this command:
DoCmd.OpenForm "ProjectF", , , "[ProjectID] = " & Me!ProjectID.Value & ""

Access VBA: Attachment image won't load in form

I have a table that contains items, their location, and an attachment photo of the item. The location is set up by row #-shelves #-shelf #. For example 2-3-4 would be in the second row on the third set of shelves on the fourth shelf down. I have another form that allows users to search by shelf. Basically, they enter the first two numbers and I do this.
DoCmd.OpenForm "fReview", , , "Location Like '" & locStr & "*'"
Where 'locStr' is the string containing 2-3 (the first two numbers), and when the form fReview opens, it should show all items on all shelves of the second row, third shelf unit.
This part works just fine. However, when fReview opens, the image part of the attachment field that I put on the form stays blank. The rest of the fields populate with no problems. When I close the form and open it again normally (with no Where condition), the image works perfectly (although it does blink a few times like it is refreshing multiple times which is weird). The form is linked to the table, so it should all be directly linked, so I don't know what's happening.
So, I created a brand new tiny database to test some things, and figured out my problem. Thought I'd share it, just in case somebody eventually had the same problem I did. It was actually pretty simple.
When I added the attachment field to my form, I just dragged it over from the "Add Existing Fields" bar. This linked the Attachment.FileData as the control source for the field, which seemed ok. Turns out that that isn't right for some reason. If you change the control source to simply be the field name, it works.