MovePrevious deleting text from populated label - vb.net

I am building a simple program around an Access database using VB.net, and I'm having an issue.
As shown in the screen capture provided, I have a Next Record and Previous record button to navigate the database's information on this particular tab control. The Next Record button works fine (though I would like to make it loop back to the start once Next Record is clicked on the last record), but the Previous Record button erases both name labels while still displaying the band name, country, instrument, and ID number. The code for the Previous Record button is:
Private Sub btnPrev_Click(sender As Object, e As EventArgs) Handles btnPrev.Click
Me.MusiciansBindingSource.MovePrevious()
End Sub
I have tried repopulating the data with Me.MusiciansTableAdapter.Fill(Me.MusiciansDataSet.Musicians) before the record moves back, but that didn't work. I'm at a loss for what else to try. Here is the aforementioned screen capture.
I can provide more information if needed. Thanks in advance!

Related

DataGridView resets to top when clicked after mouse scroll

I have a DataGridView control on a TabPage of a Windows Form application.
When the user moves the mouse over the DataGrid and uses the scroll wheel, the grid scrolls as expected. But when the user clicks in a cell on the screen, instead of the cell receiving focus, the DataGrid resets to the top and requires the user to scroll down again. This response is non-intuitive since it's not immediately obvious that the cell you thought you clicked on isn't there anymore.
I would be happy to prevent the DataGrid from responding to the scroll wheel until the user clicks in the grid, or preferably to maintain the current actions except not resetting to the top when first clicked.
From what I've researched here, it appears that the DataGrid is rebinding because I'm resetting the binding when the tabpage is entered (since the database might have been updated by one of the other tabs.
Private Sub TabPage1_Enter(sender As Object, e As EventArgs) Handles TabPage1.Enter
LoadTACTable()
End Sub
In LoadTACTable():
dbGetList("spSelectTACList", dtTACs, 0, 100000, Nothing) ' Record numbers are 0 based
bsTACs.DataSource = dtTACs
With gridTACs
' TOTAL Grid width = 1380
.DataSource() = bsTACs
.
.
.
(Showing only part of the code for brevity.
Is there a way to see if the TabPage is already displayed when entered? Or, is unnecessary to reset the gridTAC datasource every time I retrieve the data from the SQL database to the dtTACs datatable using my dbGetList() sub?
There are several possible solutions to your problem. One would be to not automatically rebind the datagrid but let the user do it by clicking some refresh button. That way the user would not see non-intuitive behavior.
You mentioned that the contents of one tab may need to be refreshed when the contents of other tabs are changed. Whenever the contents of a tab is changed and can affect other tabs, you could flag these other tabs (for example, by adding a star to their titles) to indicate that they no longer have the latest data. The user would then know that the tab needs to be refreshed.
There might be other solutions, but it is difficult to tell without knowing more about your use case.
With the guidance above, I believe I solved the issue:
I created a flag:
Dim TabDirty As Boolean
Then I set it in the TabPage.Leave handler:
Private Sub TabPage1_Leave(sender As Object, e As EventArgs) Handles TabPage1.Leave
dtTACs.Dispose()
TabDirty = True
End Sub
Then I just check it when I enter the TabPage:
Private Sub TabPage1_Enter(sender As Object, e As EventArgs) Handles TabPage1.Enter
If TabDirty = True Then
TabDirty = False
LoadTACTable()
End If
End Sub
So far, this appears to work - the grid is not getting reset when clicked, but I will do a bit more testing to confirm that the data is refreshed when necessary.

RDLC report for multiple checked box items in Listview in vb.net

I need a little help here.
I have a form which shows all the clients, stored in the access database, as a check-box items in a listview control. I want a user to check multiple checkboxes to view details of the selected clients and show it in the rdlc report.
I have written the following codes in VB.net at form_load event, but it only shows the last selected item.
I want some seggustion for the codes which shows details in the rdlc report for all the selected clients.
Private Sub TodaysPendingCompliances_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each SelctedCLient As ListViewItem In TodaysCompliances.ListView1.CheckedItems
Me.NoticeComplianceTableAdapter.FillByClientANDComplianceDate(Me.ComplianceDBDataSet.NoticeCompliance, SelctedCLient.Text)
Next
Me.ReportViewer1.RefreshReport()
End Sub
You help will be highly appreciated.
I beleive your problem is that NoticeComplianceTableAdapter.FillByClientANDComplianceDate overwrites the existing data with fresh data from the current iteration every time it is called, so it only holds the last iteration data.
To fix that you will either need to modify that function (or create an overload for it) to not clear the existing data, or create a temporary container that you declare before the loop, and add new data to each time, then attach the report to that temporary data.
Thank you Mr. Bradlet Uffner for you response. You reply helped in finding the solution.
The solution is to set the Clearbeforefill = False for the NoticeComplianceTableAdater
Setting Clearbeforefill to false does not clear the existing data with fresh data from the current iteration.

Losing cell data when datagridview gets focus

I know I need to provide some code, but I'm not sure what I should show, so please suggest if you can.
I have a bound datagridview on a Windows form. After the form loads and the datagridview gains focus (on mouse click), the first row (and a specific column) loses it's data, changing the cell's state to dirty. It doesn't matter where I click to bring the dgv into focus, that row/column always goes blank. What event is firing that may trigger that loss of data?
Again, any suggestions as to what code to post would be great. I know that will help answer this question.
Edit #1
This code is an infinite loop, but I'm adding it in response to a comment:
Private Sub dgQCOrders_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles dgQCOrders.CellPainting
If e.RowIndex = 0 And e.ColumnIndex = 9 Then
If e.FormattedValue <> e.Value Then
MsgBox("Changed")
Else
MsgBox("Unchanged")
End If
End If
End Sub
Edit #2:
Private Sub dgQCOrders_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles dgQCOrders.CellPainting
If e.RowIndex = 0 And e.ColumnIndex = 9 Then
If e.FormattedValue <> e.Value Then
Me.txtTest.Text = "Changed"
Else
Me.txtTest.Text = "Unchanged"
End If
End If
End Sub
This test tells me that the new value is null, it is deleting that first record (which I already knew)--still don't know how to fix it!
Edit #3
More explanation:
Currently, the only event I'm handling is form_Load, which fills the dgv using the tableadapter for my (bound) dataset. I then bind the dgv to the binding source.
I know that this error only occurs when the dgv gains focus (I tested this by setting the focus to the dgv when the form loads). I have a series of checkboxes/listboxes/textboxes on this form as well that allows the user to filter the dgv dynamically (back-end, I filter the binding source). If I filter the dgv first, the same row and the same column (their indexes do not change) maintains it's value when I move the focus to the dgv. When I clear the filter, the same row and the same column, loses it's data again.
I did have the _CellStateChanged event firing after a user makes an edit. Currently, it is commented out so the data loss isn't reflected in my dataset.
Additionally, I have another dgv on a different form, bound the exact same way, with the _CellStateChanged event and everything fires and saves correctly. I have gone through the designer coding for both forms, I can't find any setting difference between the two.
I'm losing my mind over here! Any help is GREATLY appreciated!
I decided to recreate the form from scratch and this error is no longer occuring. I have compared the two sets of code and can't find one discrepancy between them. If anyone has this problem in the future, save time and recreate all of the objects related to your dgv.
Maybe I understand that statement within the focus cell is not saved in the database table if U save
this problem I solved
add blank textbox control to your form which contain dgv and named txtFocus
placed it behand dgv and use its properties send to back Or
Evoked by the bottom of the screen so do not show it
then
before save
white then :
txtFocus.Focus()
sendKeys.send("{F2}")
only in this case U can save the data inside last cell changed in dgv
best Reg
Ashraf

Select next record on datasheet subform from separate form?

I have 2 forms. 1 subform.
The main form, MainFormF, has a subform which is hooked up to a query that takes data from a table and outputs it into a datasheet. Lets call this subform MainSubformF.
The 2nd form is loaded from a button on MainFormF. It has 2 buttons, previous and next. How do I attach these buttons to switch the next/previous record HIGHLIGHTED in the datasheet subform?
As you can see, that is what it looks like highlighted. It turns blue, if you didn't know.
The code I currently use but doesn't switch the selected records at all is this:
Private Sub Command65_Click()
On Error GoTo new_Err
Forms!MainformF!MainSubformF.SetFocus 'sets the focus to MainSubformF
DoCmd.RunCommand acCmdRecordsGoToNew
new_Err:
End Sub
For the button to open up the More Info form, it takes information from a text box (lets name it InfoTxt) with this as it's control source:
=[MainSubformF].[Form]![ProjectID]
I am thinking I can do something with that variable, like add +1 to it so when the button is clicked it adds +1 to the ProjectID? I don't think that will work now that I am typing this out, but I'll keep this here in case I am right... though I am thinking further into it and ProjectID's aren't always +1, as in case a record was deleted it may go 1,2,3,5,6 and if you get to 3 then click next it'll do nothing as it'll go to 4 not 5.
I simply don't have time to write out a complete answer, but Dev Ashish is a well-respected developer in the Access community and he devised a way to determine which records have been selected. My guess is you'll need to bookmark them somehow. Start with this Sub that Dev wrote:
Determine selected records in datasheet view

Problem with datagridview and AddNew

I've created a VB 2008 program to track work requests. It all works perfectly on a VISTA box, but I am having an issue with the program on an XP environment with adding new records.
Basically I've got 2 tabs: TAB 1 holds a datagridview with limited info and a calendar. Selecting dates on the calendar change the info in the datagridview. TAB 2 holds all the available info for that record in text/combo boxes. Both the datagridview and text boxes use the same Binding Source, so they are always in sync whenever the user selects a row from the datagridview. When you select the NEW button, TAB 2 appears with all the text boxes empty so the user can add data. If you look back on TAB 1, you see an empty, new row added to the datagridview (user can not directly add a row in the datagridview as AllowUserToAdd is set to false). If you let the app stay in the AddNew record state on VISTA, you remain on that new record until you select SAVE or CANCEL. On XP, however, after 1 minute time lapse, all the empty fields will eventually fill in with an existing record for that particular calendar day. When you look back on TAB 1, you no longer see the new empty row, you only see existing records previously saved.
Any ideas on how to resolve?? Thanks for any assistance.
Here is the code for adding new records:
Private Sub cmdNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNew.Click
'Focus on Work tab
TabControl1.SelectedTab = tabWork
'Change the files from read-only
bEditMode = True
ChangeEditMode()
'Clear the current information stored in the fields
Try
Me.BindingContext(WorkRequestBindingSource).AddNew()
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
'Hidden text boxes populate with current selected calendar
'Used to populate TimeIn and DateNeed because if never clicked on, will populate as NULL on save
dtpDateNeed.Text = txtDate.Text
dtpTimeIn.Text = txtTime.Text
End Sub
This is definitely an environmental issue. To solve the problem I would need to know which browsers you are using on each machine and some of the settings on each.
It sounds like the XP machine is refreshing the page after a timeout period and therefore munging the new record. I have seen that happen before and it stinks.
You might need to consider saving some more state information in the viewstate to catch that kind of thing.
If the code is exactly the same I wonder if it is an environment issue e.g. something like different international options or version of framework?