datagridview will not update

T

thomasp

I know this is a vague question, but I am not sure what information to give.
I am using VB2005 beta and the datagridview is pulling data from one of
three tables in an Access database. For some reason when I edit the feilds
that I have not set as readonly, the changes do not get written to the
database. I have the code that loads the datagridview posted below. Thanks
for any suggestions.

Thanks,

Thomas

Private Sub frmViewTables_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Variable used to track if the form is loading
'it will be used to keep some events from running
'when the form is loading

bolIsLoading = True
Me.Cursor = Cursors.WaitCursor
Me.Refresh()

'Set the form up based on which Table will be displayed
Select Case intDataTable
Case Is = 1
Me.LCMRTableAdapter.Fill(Me.TAMDataSet.LCMR)
Me.DataGridView1.DataSource = Me.TAMDataSet.LCMR
Me.Text = "LCMR DataTable"
Case Is = 2
Me.Q36TableAdapter.Fill(Me.TAMDataSet.Q36)
Me.DataGridView1.DataSource = Me.TAMDataSet.Q36
Me.Text = "Q36 DataTable"
Case Is = 3
Me.UTAMSTableAdapter.Fill(Me.TAMDataSet.UTAMS)
Me.DataGridView1.DataSource = Me.TAMDataSet.UTAMS
Me.Text = "UTAMS DataTable"
End Select

'Set up the header row
With DataGridView1.ColumnHeadersDefaultCellStyle
.BackColor = Color.Navy
.ForeColor = Color.White
.Font = New Font(DataGridView1.Font, FontStyle.Bold)
End With

' Create a new cell style.
Dim style As New DataGridViewCellStyle
With style
.BackColor = Color.Beige
'.ForeColor = Color.Brown
End With

With DataGridView1
.EditMode = DataGridViewEditMode.EditOnEnter
.AutoSizeRowsMode = _
DataGridViewAutoSizeRowsMode.DisplayedCells
.AutoSizeColumnsMode = _
DataGridViewAutoSizeColumnsMode.DisplayedCells
.ColumnHeadersBorderStyle = _
DataGridViewHeaderBorderStyle.Raised
.ColumnHeadersVisible = True
.CellBorderStyle = _
DataGridViewCellBorderStyle.Single
.GridColor = SystemColors.ActiveBorder
.AllowUserToAddRows = False
.AllowUserToOrderColumns = True
.AllowUserToResizeColumns = True
.BackgroundColor = Color.Honeydew

.Columns("DTG").DefaultCellStyle.Format = "dd-MMM-yy HH:mm:ss"
.Columns("Distance").DefaultCellStyle.Alignment =
DataGridViewContentAlignment.MiddleRight
.Columns("ID").ReadOnly = True


Select Case intDataTable
Case Is = 1
.Columns("Distance").ReadOnly = True
.Columns("Direction").ReadOnly = True
.Columns("RDistance").ReadOnly = True
.Columns("RDirection").ReadOnly = True
Case Is = 2
.Columns("Distance").ReadOnly = True
.Columns("Direction").ReadOnly = True
.Columns("RDistance").ReadOnly = True
.Columns("RDirection").ReadOnly = True
.Columns("Db").ReadOnly = True
.Columns("Velocity").ReadOnly = True
Case Is = 3

End Select


End With

' Apply the style as the default cell style.
DataGridView1.AlternatingRowsDefaultCellStyle = style

Me.Cursor = Cursors.Default
Me.Refresh()

'form has finished loading
bolIsLoading = False

End Sub
 
C

Cor Ligthert [MVP]

Thomas,

I see a lot of non relevant code for the update. However is there some code
to update as well?

Cor
 
T

thomasp

Well, that may be my problem. I thought that as long as the field was not
set to readonly and I had editonenter set that VB would handle the updating.
I was not aware that I needed to add code for the update to occur. Please
point me in the direction of what code I need to have the datagridview
update the database.

Thanks,

Thomas
 
C

Cor Ligthert [MVP]

Thomas,

This is absolute not the right sample, however it shows you at least how to
update.

Better is of course to use an update button for an update. Than you have as
well to check for errors as by instance concurrency errors (that is if
somebody made changes in the maintime). However in my opinion is it nice to
see the basic. (The absolute most simple update version as there is, is at
the bottom).

This sample does a little bit it in the way as you thought it was working.

http://www.windowsformsdatagridhelp.com/default.aspx?ID=6510b464-76bf-43a9-9707-5595f8147624

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top