VB.NET - Unable to click data within datagridview - vb.net

I have a datagridview in a form and it opens within a panel. When it opens you can't click any of the cells in table. You can click the cells when the form opens not in the panel. I'm guessing that it's something to do with the way the form opens within the panel, But i'm not sure.
I'm able to reorder the table and resize rows.
People.WindowState = FormWindowState.Maximized
People.FormBorderStyle = Windows.Forms.FormBorderStyle.None
People.Visible = True
Panel2.Controls.Add(People)
Image of table within panel

If you cannot or will not extract your datagridview from your people form (and throw the peopleform away), add this to the People form:
Public Readonly Property TheGrid As DataGridView
Get
Return Me.DataGridViewNameHere
End Get
End Property
Then add the grid to the panel, not the whole form:
Panel2.Controls.Add(People.TheGrid)

Related

Datagridview menuitem - get data of datagridview row

I am using a Datagridview, and if I right click on a row in the Datagridview I am catching the Datagridview MouseClick handler. Inside this handler I create a menuItem, if I click one entry in this menuItem I want to execute some code, and this code should get some data from the row I have selected in the Datagridview. How can I do this?
I am using this kind of code to create menuItem entrys:
Dim firefox As New MenuItem("Firefox", AddressOf contextMenu_ItemClicked)
firefox.Tag = "firefox"
Another question, do I need to add this tag, or am I also able to read out the name of the menuitem in the contextMenu_ItemClicked function?
Thanks!

Do you have to show every tab before all textboxes actually populate?

I have a vb.net form that uses multiple textboxes across several different tabs. Within one of those tabs, I have a sub set of tabs. My save functionality calls stored procs for each tab and cycles through the values on each page to either do an update or a "add new". I noticed that while testing, some of the pages do not save or update any of the values in the textboxes. After a few days of investigating, I realized that if I edit something, then physically click through the other tabs, it all saves/updates properly. If I don't click through them, they don't all save. Is there a reason for this that I am missing? When you enter a search value, I cycle through the pages and populate them all at the same time so I was assuming it wrote those values BEFORE it physically rendered...I guess I am wrong?
From the TabPage documentation Remarks section
Controls contained in a TabPage are not created until the tab page is shown, and any data bindings in these controls are not activated until the tab page is shown.
So the answer to your question is "Yes the tabpage must be shown".
However, the definition of "shown" is subject to interpretation. In reality, all you need to do set the TabPage.Visible property to True and not actually cycle through and display each TabPage.
A recursive scan of the form for TabPage controls will work:
Private Shared Sub TabPagesVisible(parent As Control)
For Each c As Control In parent.Controls
If TypeOf c Is TabPage Then c.Visible = True
TabPagesVisible(c)
Next
End Sub
Example usage:
Sub SaveFormTabData()
TabPagesVisible(Me) ' Me refers to the containing form
' code to save control data
End Sub

can docmd.gotorecord,,acnew open in new window?

I have a form which is bound to a table, and lets a user scroll through existing records in the table and make changes. I'm now trying to build a button which allows the user to insert a new record. So far I have a button with some basic vba:
Private Sub btnNew_Click()
DoCmd.GoToRecord , , acNewRec
End Sub
This opens a new record in the same form and has no way of assuring a user that the record has been saved. What i would really like is for the this to open a new 'pop up'form with a save button on
how would i do this?
Go to the design view of the Form, add a button name it saveBtn. Under its properties, set the visibility as No. Now in the Form Current method, check if the form has the new record, if so make the button visible.
Private Sub Form_Current()
Me.saveBtn.Visible = Me.NewRecord
End Sub
Using this method, the current form could be used for navigation and editing and when it sits on a new record a Save button will be available where in you could add the code to run a Save command or close the Form, which by default will save the record.

VB.Net datagridview on tab page not returning row count unless user has viewed it

I have a tabcontrol. Each tabpage on the tabcontrol contains a datagridview. These are created programmatically.
Later I am reading values from the datagridviews and writing them to a Word document.
If the user has clicked on the tab page, the datagridview reports its correct row count.
If the user has not viewed the tab page, the datagridview .rowcount = 0
Is there something I can do to force the datagridview to reflect its actual rowcount?
I am navigating to the tab containing the datagridview by name (tcPlanFeeTab) with the following code:
For Each tp As TabPage In frmSvcFee.tcPlanFee.TabPages
'find the fee tab
If tp.Text = tcPlanFeeTab Then 'this is the fee tab
'select the tp so the datagridview is activated
tp.Select()
For Each ctl As Control In tp.Controls 'find the datagridview on the rates tab
If TypeOf ctl Is DataGridView Then
Dim D As DataGridView = ctl
MessageBox.Show(D.RowCount)
There is no way (that I know of) to force the grid to finish binding the data before the grid has been shown.
This is an optimization within the DataGridView itself.
Your best bet is to go to the underlying data source instead.

Values is not appearing in Current active Form

Using VB.Net (Windows Application)
I have one main form(Data entry form), i creating many form at run time.
Code for creating a multiple form at run time.
Button1 click
If IsNothing(frm) OrElse frm.IsDisposed Then
newfrm = New frmEntry
End If
newfrm.Show()
I have popup windows for selcting the value in the Data entry form.
Code for selcting the value from popup windows
Popup Window code
If e.KeyCode = Keys.Enter Then
frmEntry.txtbox1.Text = gridview1.Rows(crRow).Cells("code").Value.ToString().Trim()
End If
The above popup window code is working for Data Entry Form, but it is not working for new forms (at run time)
When i select the value from popup windows means, it is appearing in frmentry textbox, not in newfrm textbox.
Popup windows selected value should appear in current active form.
What wrong in my code.
Need VB.Net Code Help
If the form you open the popup from is what you need to change values in, have you considered passing a reference to the opening form to the popup when you open it? So that you have direct access to the form that has the controls that will need updated?
This constructor in the popup window:
Private mOpeningForm As frmEntry
Public Sub New(OpeningForm As frmEntry)
InitializeComponent()
mOpeningForm = OpeningForm
End Sub
This modified to use the reference to the form sent to the popup form:
If e.KeyCode = Keys.Enter Then
mOpeningForm.txtbox1.Text = gridview1.Rows(crRow).Cells("code").Value.ToString().Trim()
End If
This in the form when the window is being created at runTime:
If IsNothing(mEntryForm) OrElse mEntryForm.IsDisposed Then
mEntryForm= New frmEntry(me)
End If
mEntryForm.Show()
At the top level of the Data Form Class (The one creating the popups)
private mEntryForm as frmEntry
That will allow you to have a reference to the Instance of frmEntry from anywhere in the data form class. (Note that I changed the name of the popup form instance in for the button click event code too)