Click here to Skip to main content
15,886,801 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionProblem with Listview Pin
nazimghori17-Jul-09 5:08
nazimghori17-Jul-09 5:08 
AnswerRe: Problem with Listview Pin
nlarson1117-Jul-09 5:32
nlarson1117-Jul-09 5:32 
QuestionRe: Problem with Listview Pin
nazimghori17-Jul-09 17:41
nazimghori17-Jul-09 17:41 
QuestionImporting CSV files with embedded commas Pin
Astitva2317-Jul-09 1:04
Astitva2317-Jul-09 1:04 
AnswerRe: Importing CSV files with embedded commas Pin
riced17-Jul-09 7:26
riced17-Jul-09 7:26 
QuestionInput string was not in a correct format Pin
hsuresh16-Jul-09 23:50
hsuresh16-Jul-09 23:50 
AnswerRe: Input string was not in a correct format Pin
Luc Pattyn17-Jul-09 0:51
sitebuilderLuc Pattyn17-Jul-09 0:51 
QuestionSerialization and deserialization - can't view records in a datagrid nor save in a dataset Pin
BluesEnd16-Jul-09 17:50
BluesEnd16-Jul-09 17:50 
Hi,
I’m following a tutorial using serialization/saving records.
I can make records, display them ok in a datgridview and then save them ok using serialization. Then I can reopen the programme and reload the dataset from the deserialised file, and show the records ok in the datagrid view - but I cannot add any more records to the datagridview.
I’d be grateful for any help/advice/assistance.
Regards,
Steve

Here is my code:

Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary

Public Class Frm_DataEntry
Dim ThePoint As New Point(540, 150)
Public TheRecord As DataRow
Dim ii As Integer

Private Sub Frm_DataEntry_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Location = ThePoint
End Sub

Private Sub Tbx01_FirstName_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tbx01_FirstName.Enter
Tbx01_FirstName.Clear()
Tbx02_LastName.Clear()
Tbx03_Phone.Clear()
End Sub

Private Sub Btn01_Save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn01_Save.Click
TheRecord = Frm_Mainform.dt_Table.NewRow

TheRecord(Frm_Mainform.dt_Col02_FirstName) = Tbx01_FirstName.Text
TheRecord(Frm_Mainform.dt_Col03_LastName) = Tbx02_LastName.Text

Frm_Mainform.dt_Table.Rows.Add(TheRecord)
Frm01_WithDGV.DGV01.DataSource = Frm_Mainform.ds_Dataset
Frm01_WithDGV.DGV01.DataMember = Frm_Mainform.dt_Table.ToString

Frm01_WithDGV.DGV01_BS_Col01_PKey.DataPropertyName = Frm_Mainform.dt_Col01_PKey.ToString
Frm01_WithDGV.DGV01_BS_Col02_FirstName.DataPropertyName = Frm_Mainform.dt_Col02_FirstName.ToString
Frm01_WithDGV.DGV01_BS_Col03_LastName.DataPropertyName = Frm_Mainform.dt_Col03_LastName.ToString

Dim ii As Integer
ii = Frm_Mainform.dt_Table.Rows.Count
MessageBox.Show(ii)

End Sub

Private Sub Btn02_SaveAndClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn02_SaveAndClose.Click
Dim Filename As String = "PermitToWork.pmt"
Dim fStream As FileStream

Frm01_WithDGV.DGV01.DataSource = Frm_Mainform.ds_Dataset
Frm01_WithDGV.DGV01.DataMember = Frm_Mainform.dt_Table.ToString

Frm01_WithDGV.DGV01_BS_Col01_PKey.Width = 90
Frm01_WithDGV.DGV01_BS_Col02_FirstName.Width = 125
Frm01_WithDGV.DGV01_BS_Col03_LastName.Width = 125
Frm01_WithDGV.DGV01_BS_Col04_Date.Width = 125
Frm01_WithDGV.DGV01_BS_Col01_PKey.DataPropertyName = Frm_Mainform.dt_Col01_PKey.ToString
Frm01_WithDGV.DGV01_BS_Col02_FirstName.DataPropertyName = Frm_Mainform.dt_Col02_FirstName.ToString
Frm01_WithDGV.DGV01_BS_Col03_LastName.DataPropertyName = Frm_Mainform.dt_Col03_LastName.ToString

If File.Exists(Filename) Then
Try
fStream = New FileStream(Filename, FileMode.Create)
Dim binFormat As New BinaryFormatter
binFormat.Serialize(fStream, Frm_Mainform.ds_Dataset)
Catch anex As ArgumentNullException
MsgBox("The inventory could not be accessed")
Catch ex As SerializationException
MsgBox("The application failed to retrieve the inventory")
Finally
fStream.Close()
End Try
Else
Return
End If

Frm_Mainform.Close()
End Sub

Private Sub Btn03_Reload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn03_Reload.Click
Dim Filename As String = "PermitToWork.pmt"
Dim fStream As FileStream

If File.Exists(Filename) Then
Try
fStream = New FileStream(Filename, FileMode.OpenOrCreate, FileAccess.ReadWrite)
Dim binFormat As New BinaryFormatter
Frm_Mainform.ds_Dataset = binFormat.Deserialize(fStream)

Frm01_WithDGV.DGV01.DataSource = Frm_Mainform.ds_Dataset
Frm01_WithDGV.DGV01.DataMember = Frm_Mainform.dt_Table.ToString

Frm01_WithDGV.DGV01_BS_Col01_PKey.Width = 90
Frm01_WithDGV.DGV01_BS_Col02_FirstName.Width = 125
Frm01_WithDGV.DGV01_BS_Col03_LastName.Width = 125
Frm01_WithDGV.DGV01_BS_Col04_Date.Width = 125
Frm01_WithDGV.DGV01_BS_Col01_PKey.DataPropertyName = Frm_Mainform.dt_Col01_PKey.ToString
Frm01_WithDGV.DGV01_BS_Col02_FirstName.DataPropertyName = Frm_Mainform.dt_Col02_FirstName.ToString
Frm01_WithDGV.DGV01_BS_Col03_LastName.DataPropertyName = Frm_Mainform.dt_Col03_LastName.ToString

Catch anex As ArgumentNullException
MsgBox("The inventory could not be accessed")
Catch ex As SerializationException
MsgBox("The application failed to retrieve the inventory")
Finally
fStream.Close()
End Try
Else
Return
End If

Dim ii As Integer
ii = Frm01_WithDGV.DGV01.Rows.Count
MessageBox.Show(ii)

End Sub

End Class

Thanks for your help and advice!
Steve

GeneralVB2008 express, Expression Error Pin
A Wyatt16-Jul-09 11:44
A Wyatt16-Jul-09 11:44 
GeneralRe: VB2008 express, Expression Error Pin
Christian Graus16-Jul-09 14:48
protectorChristian Graus16-Jul-09 14:48 
GeneralRe: VB2008 express, Expression Error Pin
Paul Conrad18-Jul-09 19:55
professionalPaul Conrad18-Jul-09 19:55 
GeneralRe: VB2008 express, Expression Error Pin
Dave Kreskowiak16-Jul-09 15:52
mveDave Kreskowiak16-Jul-09 15:52 
GeneralRe: VB2008 express, Expression Error Pin
Luc Pattyn16-Jul-09 15:55
sitebuilderLuc Pattyn16-Jul-09 15:55 
GeneralRe: VB2008 express, Expression Error Pin
Dave Kreskowiak16-Jul-09 16:00
mveDave Kreskowiak16-Jul-09 16:00 
GeneralRe: VB2008 express, Expression Error Pin
Luc Pattyn16-Jul-09 16:11
sitebuilderLuc Pattyn16-Jul-09 16:11 
GeneralRe: VB2008 express, Expression Error Pin
A Wyatt18-Jul-09 4:11
A Wyatt18-Jul-09 4:11 
QuestionExtract/get big image (256*256, 48*48) from directory/file Pin
User 584223716-Jul-09 5:02
User 584223716-Jul-09 5:02 
AnswerRe: Extract/get big image (256*256, 48*48) from directory/file Pin
Steven J Jowett16-Jul-09 9:30
Steven J Jowett16-Jul-09 9:30 
GeneralRe: Extract/get big image (256*256, 48*48) from directory/file Pin
User 584223716-Jul-09 9:50
User 584223716-Jul-09 9:50 
QuestionFile finder [modified] Pin
subdeery16-Jul-09 1:47
subdeery16-Jul-09 1:47 
AnswerRe: File finder Pin
Rozis17-Jul-09 12:08
Rozis17-Jul-09 12:08 
GeneralRe: File finder Pin
subdeery20-Jul-09 0:38
subdeery20-Jul-09 0:38 
QuestionI want to click this button Follow twitter in webbrowser Pin
pobre1216-Jul-09 0:01
pobre1216-Jul-09 0:01 
AnswerRe: I want to click this button in webbrowser Pin
Tom Deketelaere16-Jul-09 0:14
professionalTom Deketelaere16-Jul-09 0:14 
GeneralRe: I want to click this button in webbrowser Pin
Christian Graus16-Jul-09 1:32
protectorChristian Graus16-Jul-09 1:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.