Display A Picture From Database - vb.net

I have a datagridview and when I click inside, it opens another form with the information that is inside the datagridview.
In my Access database I have OLE Object with a picture (bitmap) and I want to display that in the form info too.
This is the code that I have to get the info when I click in the datagridview:
Private Sub DataGridView1_RowHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.RowHeaderMouseClick
Dim curForm As Form = New Form
With curForm
info.TextBox1.Text = DataGridView1.SelectedRows(0).Cells(1).Value
info.TextBox2.Text = DataGridView1.SelectedRows(0).Cells(2).Value
info.TextBox3.Text = DataGridView1.SelectedRows(0).Cells(3).Value
info.TextBox4.Text = DataGridView1.SelectedRows(0).Cells(4).Value
info.TextBox5.Text = DataGridView1.SelectedRows(0).Cells(5).Value
info.Show()
End With
End Sub

Related

Updating Database from form entry in VB.net

I am trying to update an access database with the data entered into a form. When I hit the insert button, it updates the datagridview in the other form (so I can see the data), but it does not populate the database. What am I missing?
Dim newCoinsRow As CoinsDatabaseDataSet.CoinsRow
newCoinsRow = frmCollection.CoinsDatabaseDataSet.Coins.NewCoinsRow
newCoinsRow.Name = strName
newCoinsRow.Year = intYear
newCoinsRow.FaceValue = decFaceValue
newCoinsRow.Currency = strCurrency
newCoinsRow.Metal = strMetal
newCoinsRow.Weight = decWeight
newCoinsRow.Value = decValue
newCoinsRow.IsEncapsulated = boolEncapsulated
frmCollection.CoinsDatabaseDataSet.Coins.Rows.Add(newCoinsRow)
frmCollection.CoinsTableAdapter.Update(frmCollection.CoinsDatabaseDataSet.Coins)
In the form with the datagrid view, I have this:
Private Sub frmCollection_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.CoinsTableAdapter.Fill(Me.CoinsDatabaseDataSet.Coins)
End Sub

How to access user controls' text box from a form?

Public Sub patientListView_MouseClick(sender As Object, e As MouseEventArgs) Handles patientListView.MouseClick
patientID = patientListView.FocusedItem.SubItems(1).Text
frmMain.Label1.Text = patientID.ToString
frmBillingManagement.lblTry.Text = patientID.ToString
End Sub
Note: frmBillingManagement is a user control
Those code are from frmBillingPatient..
my problem is when I select a row in patientListView i cant put it into the lblTry in frmBillingManagement, its not working. But its working with the frmMain which is a form.

Multiple Child Forms behaving strangely

I have created a Form that dynamically loads buttons into a panel on the left hand side of an MDI Parent Form. Once loaded, a user can click one of the buttons, and a Child form will load into the right hand side, docked at the top and containing a datagridview with the results of some query. Each child form that is added sits directly below the previous one, due to the docking top property.
All this seems to work fine, however when more than one child forms is open the behaviour of the forms is unexpected. If I click on any child form other than the bottom form, it immediately moves its position to the bottom, rather than staying in place. Is there a way to deal with this - or is there something I am doing in my code that means this is happening - such as trying to dock a window?
My code is below.
Private Sub TableLookupForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim mySQLString As String = "Button SQL Query"
Dim i As Integer = 0
myVector.mySQLString = mySQLString
For Each row In myVector.myIngresDataset.Tables(0).Rows
Dim myBtn As New Button
i = i + 1
myBtn.Text = row("table_name")
myBtn.Name = "Btn" & i
myBtn.Dock = DockStyle.Top
AddHandler myBtn.Click, AddressOf Me.Button_Click
Me.Panel1.Controls.Add(myBtn)
Me.Panel1.Controls.SetChildIndex(myBtn, 0)
Next
End Sub
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim myTableForm As New TableChildForm
myTableForm.MdiParent = Me
myTableForm.Dock = DockStyle.Top
myTableForm.Tag = sender.text
myTableForm.Text = sender.text
Dim mySQLString As String = "Form SQL Query"
myVector.mySQLString = mySQLString
myTableForm.myTableData.DataSource = myVector.myIngresDataset.Tables(0)
myTableForm.Show()
End Sub
Thanks,
Paul.

How to refresh a DataGridView when a dialog form is closed

I am trying to refresh a datagirdview when i add a new record using a dialog form. I would like to know how can i refresh my datagirdview. I have two Win Forms . Form A is called FrmContactDetailList which is having a datagridview which i is showing data from sql server. Below first block of code is used to bind data to the grid. which is given in form load event and also in this form i have a Button called "Add New Record" . Once i press this button its opening a win form which is opening another form. Below is that code which i used to open this in by button click event.
This will open Form B. Form is called FrmClientDetails. This form will have a text box and a save button . So once i enter the new name in the text box and press save i want the datagirdview which is in Form A to be updated . and show the new record once i close Form B. how can i achieve this.
This Code is used to bind the datagridview. I have given this is the form load event.
Sub GetContactList()
Dim BindData As New VoucherClass
Dim dt As DataTable = BindData .Get_Client_List
DataGridView.DataSource = dt
End Sub
Private Sub FrmContactDetailsList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GetContactList()
End Sub
I have using this code to open the dialog form to enter the new data.
Private Sub BtnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOpen.Click
Dim FrmNewContact As New FrmClientDetails
FrmNewContact.Owner = Me
FrmNewContact.ShowDialog()
End Sub
When the binding data change it is automatically reflected to the data grid view that is bond.
Edit:
Handle the FrmNewContact's Closing event. You can refresh your datagridview in that sub.
Dim WithEvents dialog As New FrmNewContact
Sub done() Handles dialog.FormClosed
Me.DataGridView1.Refresh()
End Sub
Next edit:
Dim BindData As New VoucherClass
Dim dt As DataTable = BindData .Get_Client_List
Declare them outside of the sub. So you should have this:
Dim BindData as VoucherClass
Dim dt as DataTable
Sub GetContactList()
BindData = New VoucherClass
dt = BindData .Get_Client_List
DataGridView.DataSource = dt
End Sub
Try this: Instead of FrmNewContact.ShowDialog() If FrmNewContact.ShowDialog() = DialogResult.OK Then Me.DataFridView.Refresh() End IF You may need to include a setter for your dialog result at the close action for your modal. Me.DialogResult = DialogResult.OK Me.Close()

combobox not being populated

I have a windows form project with a main form. There is a textbox leave event that opens a new form. In that new forms load event i have a combobox item loop that populates the combobox items. It works perfectly fine if run on the main form but doesnt work on the second form. Why doesn't the comboboxes on the secondary form populate when that form is opened via a textbox_leave event from the main form?
this is the leave event
Private Sub tbChartTitle_Leave(sender As Object, e As System.EventArgs) Handles tbChartTitle.Leave
If Not tbChartTitle.Text = Nothing Then
frmTitleAttributes.Show()
End If
End Sub
This is the code that populates one of the comboboxes on the second form (it works if run on a combobox on the main form)
Private Sub frmTitleAttributes_Load(sender As Object, e As System.EventArgs) Handles Me.Load
InitializeComponent()
AddFonts()
End Sub
Private Sub AddFonts()
' Get the installed fonts collection.
Dim allFonts As New Drawing.Text.InstalledFontCollection
' Get an array of the system's font familiies.
Dim fontFamilies() As FontFamily = allFonts.Families
' Display the font families.
For i As Integer = 0 To fontFamilies.Length - 1
cbxTitleFonts.Items.Add(fontFamilies(i).Name)
Next
End Sub
make sure that the Load handler is hit after you show your form (use break point)
also you can try to call it in the Shown event
Private Sub frmTitleAttributes_Shown(sender as Object, e as EventArgs) _
Handles frmTitleAttributes.Shown
AddFonts()
End Sub