By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,239 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,239 IT Pros & Developers. It's quick & easy.

datagridview will not update

P: n/a

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

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Thomas,

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

Cor
<th*****@msala.net> schreef in bericht
news:43***********************@news.newsdemon.com. ..

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

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

Nov 21 '05 #2

P: n/a

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

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #3

P: n/a
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....7-5595f8147624

I hope this helps,

Cor

<th*****@msala.net> schreef in bericht
news:43**********************@news.newsdemon.com.. .

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

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.