473,594 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datagridview will not update


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_L oad(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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.WaitCur sor
Me.Refresh()

'Set the form up based on which Table will be displayed
Select Case intDataTable
Case Is = 1
Me.LCMRTableAda pter.Fill(Me.TA MDataSet.LCMR)
Me.DataGridView 1.DataSource = Me.TAMDataSet.L CMR
Me.Text = "LCMR DataTable"
Case Is = 2
Me.Q36TableAdap ter.Fill(Me.TAM DataSet.Q36)
Me.DataGridView 1.DataSource = Me.TAMDataSet.Q 36
Me.Text = "Q36 DataTable"
Case Is = 3
Me.UTAMSTableAd apter.Fill(Me.T AMDataSet.UTAMS )
Me.DataGridView 1.DataSource = Me.TAMDataSet.U TAMS
Me.Text = "UTAMS DataTable"
End Select

'Set up the header row
With DataGridView1.C olumnHeadersDef aultCellStyle
.BackColor = Color.Navy
.ForeColor = Color.White
.Font = New Font(DataGridVi ew1.Font, FontStyle.Bold)
End With

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

With DataGridView1
.EditMode = DataGridViewEdi tMode.EditOnEnt er
.AutoSizeRowsMo de = _
DataGridViewAut oSizeRowsMode.D isplayedCells
.AutoSizeColumn sMode = _
DataGridViewAut oSizeColumnsMod e.DisplayedCell s
.ColumnHeadersB orderStyle = _
DataGridViewHea derBorderStyle. Raised
.ColumnHeadersV isible = True
.CellBorderStyl e = _
DataGridViewCel lBorderStyle.Si ngle
.GridColor = SystemColors.Ac tiveBorder
.AllowUserToAdd Rows = False
.AllowUserToOrd erColumns = True
.AllowUserToRes izeColumns = True
.BackgroundColo r = Color.Honeydew

.Columns("DTG") .DefaultCellSty le.Format = "dd-MMM-yy HH:mm:ss"
.Columns("Dista nce").DefaultCe llStyle.Alignme nt =
DataGridViewCon tentAlignment.M iddleRight
.Columns("ID"). ReadOnly = True
Select Case intDataTable
Case Is = 1
.Columns("Dista nce").ReadOnly = True
.Columns("Direc tion").ReadOnly = True
.Columns("RDist ance").ReadOnly = True
.Columns("RDire ction").ReadOnl y = True
Case Is = 2
.Columns("Dista nce").ReadOnly = True
.Columns("Direc tion").ReadOnly = True
.Columns("RDist ance").ReadOnly = True
.Columns("RDire ction").ReadOnl y = True
.Columns("Db"). ReadOnly = True
.Columns("Veloc ity").ReadOnly = True
Case Is = 3

End Select
End With

' Apply the style as the default cell style.
DataGridView1.A lternatingRowsD efaultCellStyle = 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.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #1
3 11763
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_L oad(ByVal sender As System.Object, ByVal e
As
System.EventArg s) 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.WaitCur sor
Me.Refresh()

'Set the form up based on which Table will be displayed
Select Case intDataTable
Case Is = 1
Me.LCMRTableAda pter.Fill(Me.TA MDataSet.LCMR)
Me.DataGridView 1.DataSource = Me.TAMDataSet.L CMR
Me.Text = "LCMR DataTable"
Case Is = 2
Me.Q36TableAdap ter.Fill(Me.TAM DataSet.Q36)
Me.DataGridView 1.DataSource = Me.TAMDataSet.Q 36
Me.Text = "Q36 DataTable"
Case Is = 3
Me.UTAMSTableAd apter.Fill(Me.T AMDataSet.UTAMS )
Me.DataGridView 1.DataSource = Me.TAMDataSet.U TAMS
Me.Text = "UTAMS DataTable"
End Select

'Set up the header row
With DataGridView1.C olumnHeadersDef aultCellStyle
.BackColor = Color.Navy
.ForeColor = Color.White
.Font = New Font(DataGridVi ew1.Font, FontStyle.Bold)
End With

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

With DataGridView1
.EditMode = DataGridViewEdi tMode.EditOnEnt er
.AutoSizeRowsMo de = _
DataGridViewAut oSizeRowsMode.D isplayedCells
.AutoSizeColumn sMode = _
DataGridViewAut oSizeColumnsMod e.DisplayedCell s
.ColumnHeadersB orderStyle = _
DataGridViewHea derBorderStyle. Raised
.ColumnHeadersV isible = True
.CellBorderStyl e = _
DataGridViewCel lBorderStyle.Si ngle
.GridColor = SystemColors.Ac tiveBorder
.AllowUserToAdd Rows = False
.AllowUserToOrd erColumns = True
.AllowUserToRes izeColumns = True
.BackgroundColo r = Color.Honeydew

.Columns("DTG") .DefaultCellSty le.Format = "dd-MMM-yy HH:mm:ss"
.Columns("Dista nce").DefaultCe llStyle.Alignme nt =
DataGridViewCon tentAlignment.M iddleRight
.Columns("ID"). ReadOnly = True
Select Case intDataTable
Case Is = 1
.Columns("Dista nce").ReadOnly = True
.Columns("Direc tion").ReadOnly = True
.Columns("RDist ance").ReadOnly = True
.Columns("RDire ction").ReadOnl y = True
Case Is = 2
.Columns("Dista nce").ReadOnly = True
.Columns("Direc tion").ReadOnly = True
.Columns("RDist ance").ReadOnly = True
.Columns("RDire ction").ReadOnl y = True
.Columns("Db"). ReadOnly = True
.Columns("Veloc ity").ReadOnly = True
Case Is = 3

End Select
End With

' Apply the style as the default cell style.
DataGridView1.A lternatingRowsD efaultCellStyle = 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.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

Nov 21 '05 #2

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.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #3
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.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
39470
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got some DataGridViewTextBoxCell, DataGridViewComboBoxCell etc, i want to export all that to XML.. Any help is greatly appreciated.
0
6940
by: TNSFED | last post by:
I have a dilemma when trying to delete a row from the DataGridView. Here is a sample of my code: private void dgv_EQUPS_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { fDeleteRow = false; if (chx_DeleteFlag.Checked) {
2
24527
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should you update after closing the grid/form, etc.? Also, can you tell me the best book to buy that fully explains the DataGridView control? Thanks.
11
27291
by: Kevin | last post by:
I've been searching forever for examples of saving data changes in a DataGridView. There's all kinds of examples, but none really show how to save changes. Someone please help me. I have a Windows Forms program with a DataGridView and a BindingSource added to a form. Here is the code I'm using to populate the grid: Dim CRClassesTableAdapter As SqlDataAdapter Dim CRClassesTable As New DataTable()
4
21286
by: Hexman | last post by:
Hello All, I'd like to find out the best way to add a cb column to a dgv and process efficiently. I see at least two ways of doing it. ------------------------------- 1) Add a cb to the dgv, iterate thru the dgv and update the bound fields if the cb has been checked. Then do the update and accept changes. How do I access the cb and its checked status? How to iterate thru dgv? Dim cbSelCol As New DataGridViewCheckBoxColumn
2
4684
by: Martin | last post by:
Hi all, This is the situation... DatagridView Control with datasource set to datatable. I want the user to be able to delete x number of rows by selecting a row with mouse then clicking a 'delete' button. Then user clicks a 'Commit' button to update the database.
7
15640
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is there an equivalent property for the DataGridView? I have searched, but have not found one. I would like the user to be able to see all the columns of the table on one screen - thus eliminating the need to use the horizontal scroll bar to view...
4
4850
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a sql DataAdapter (da) da.SelectCommand.CommandText = "Select * from Servertbl1" da.Fill(ds, "tbl1") so far, so good. If I add a row to the datagridview I use the following sqlDataAdapter code to update the server table - which works OK when...
1
1605
nev
by: nev | last post by:
Happy Easter to all! I have a problem with a datagridview. I placed code in a button click event as follows: dim dtt as datatable = dataset.employees.copy dtt.DefaultView.RowFilter = "='" & Me.LastNameTextBox.Text & "'" Me.DataGridView.DataSource = "" Me.DataGridView.DataSource = dtt
7
1806
by: Bill Schanks | last post by:
VB.NET 2005 SQL Server 2000 I have a datagridview that users will update. When there are only a few records the update is fine. However when they update 100-200 of the rows the udpate can take 2+ Mins. Is this normal performance, as the datagridview was not meant to update this many records at once?
0
7954
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8016
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5836
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5415
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3905
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2391
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1487
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1218
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.