473,725 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagridview doesn't update current row values

VB2008
I have a DataGridView with MultiSelect = True and
SelectionMode=F ullRowSelect. One of the columns is a checkbox column. I have
a function that goes through all the selected rows and sets the value of
this column.

For Each row In DataGridView1.S electedRows
row.Cells("MyCh eckboxColumn"). Value = False
Next

This seems to almost work, but I noticed that sometimes it does not update
the first or the last selected row. On investigation, it seems that the
value is updated, but if the row happens to be the currentrow, the change is
not displayed until the currentrow is changed. I have managed to get around
this problem by setting CurrentCell = Nothing after I have made the changes,
but this has the undesirable side effect of clearing the selection.

Any suggestions?

TIA
Phil.

Jun 27 '08 #1
20 20322
Hi Phil,

I performed a test based on your description but didn't reproduce the
problem on my side. All selected rows in the DataGridView are updated
immediately in my test application.

I create a WinForm Application project in VS2008 and add a DataGridView and
a Button on the Form1. I add a DataGridViewChe ckBoxColumn in the
DataGridView. The following is the code in the Form1.vb:

Public Class Form1
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Me.DataGridView 1.SelectionMode =
DataGridViewSel ectionMode.Full RowSelect
Me.DataGridView 1.RowCount = 10
For i As Integer = 0 To 9
Me.DataGridView 1.Rows(i).Cells (0).Value = True
Next
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
For Each row As DataGridViewRow In Me.DataGridView 1.SelectedRows
row.Cells(0).Va lue = False
Next
End Sub
End Class

Build and run the application. Select some rows in the DataGridView with
Mouse and click the Button, all selected rows are updated immediately.
Is there any difference between your code and mine?

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 27 '08 #2

"Linda Liu[MSFT]" <v-****@online.mic rosoft.comwrote in message
news:Fj******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Phil,

I performed a test based on your description but didn't reproduce the
problem on my side. All selected rows in the DataGridView are updated
immediately in my test application.
Thanks for looking at this. My datagridview is part of a larger application,
so there is quite a lot of difference from your code. I shall try to
reproduce the problem in a smaller app. The main thing that springs to mind
that is different is that my data is populated from a datasource (OleDb -
access/jet). I'm not sure if that is relevant.

Phil.
Jun 27 '08 #3

"Linda Liu[MSFT]" <v-****@online.mic rosoft.comwrote in message
news:Fj******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Phil,

I performed a test based on your description but didn't reproduce the
problem on my side. All selected rows in the DataGridView are updated
immediately in my test application.
OK. I have managed to adapt your code to reproduce the problem.
Create the datagridview initially with no columns and replace Form_Load
as follows:

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Me.DataGridView 1.SelectionMode = DataGridViewSel ectionMode.Full RowSelect

Dim data As New DataTable
data.Columns.Ad d("Column1", Type.GetType("S ystem.Int16"))
For i As Integer = 0 To 9
data.Rows.Add(1 )
Next

Me.DataGridView 1.DataSource = data

Dim col As New DataGridViewChe ckBoxColumn
Me.DataGridView 1.Columns.Add(c ol)
col.DataPropert yName = "Column1"

End Sub

Jun 27 '08 #4
OK. I have managed to adapt your code to reproduce the problem.
Create the datagridview initially with no columns and replace Form_Load
as follows:

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Me.DataGridView 1.SelectionMode =
DataGridViewSel ectionMode.Full RowSelect

Dim data As New DataTable
data.Columns.Ad d("Column1", Type.GetType("S ystem.Int16"))
For i As Integer = 0 To 9
data.Rows.Add(1 )
Next

Me.DataGridView 1.DataSource = data

Dim col As New DataGridViewChe ckBoxColumn
Me.DataGridView 1.Columns.Add(c ol)
col.DataPropert yName = "Column1"

End Sub
It seems the problem occurs when there are two columns bound to the same
data property.
If I add:
Me.DataGridView 1.Columns.Remov e("Column1")
The problem does not occur.

In my main application I hide this column. I shall try removing it instead,
and see if that fixes it.
It does seem to be a bug in the datagridview data binding though.
Jun 27 '08 #5
In my main application I hide this column. I shall try removing it
instead,
and see if that fixes it.
It didn't fix it :-(
Not sure why, perhaps because there are other columns too.
Jun 27 '08 #6
It seems the problem occurs when there are two columns bound to the same
data property.
The reason I am doing this, is because the column does not automatically
appear as a checkbox. The underlying SQL query is of the following form:

SELECT EXISTS(subquery ), ....

For some reason the result of the EXISTS function seems to come back as an
integer in the Dataset. If there was some way to make this return a boolean,
that might solve my problem. This is OleDb (access/jet).
Jun 27 '08 #7
Hi Phil,

Thank you for your prompt reply!

I performed a test based on your sample code and did reproduce the problem
on my side. If I update the data in the data source in code directly, the
problem also exists even if there's only one DataGridViewChe ckBoxColumn in
the DataGridView.

This problem is not relevant to multiple columns' being bound to the same
data property.

The reason behind this problem is that data binding doesn't refresh data of
the current item in UI when the data in the underlying data source are
changed.

The workaround is to call the EndCurrentEdit method of the corresponding
BindingManagerB ase object associated with the data source to end current
edit to the data source and refresh the UI.

For example, after you change the value of the DataGridViewCel ls or change
the data in the data source directly, add the following line of code:
Me.BindingConte xt(data).EndCur rentEdit()
For some reason the result of the EXISTS function seems to come back as
an integer in the Dataset.

The EXISTS operator returns a value of bit. In .NET, the corresponding type
is Boolean. If a data column is of type Boolean, DataGridView will generate
a DataGridViewChe ckBoxColumn for this data column.

Is the DataTable strong-typed in your application? If so, you may open the
DataSet in the designer and select the column of the DataTable and check
the column's type in the Properties window. If not, you need to set a break
point in your code and press F5 to run the application. When the
application enters into break mode, you can check the type of the
DataTable's column.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 27 '08 #8
Hi Phil,

How about the problem now?

If you have any question, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 27 '08 #9
I performed a test based on your sample code and did reproduce the problem
on my side. If I update the data in the data source in code directly, the
problem also exists even if there's only one DataGridViewChe ckBoxColumn in
the DataGridView.
OK.
>
This problem is not relevant to multiple columns' being bound to the same
data property.
OK. That was just a theory :-)
>
The reason behind this problem is that data binding doesn't refresh data
of
the current item in UI when the data in the underlying data source are
changed.
OK. That makes sense I think. It still thinks the row is being edited, so
doesn't refresh until the current row is changed.
>
The workaround is to call the EndCurrentEdit method of the corresponding
BindingManagerB ase object associated with the data source to end current
edit to the data source and refresh the UI.
OK.
>
For example, after you change the value of the DataGridViewCel ls or change
the data in the data source directly, add the following line of code:
Me.BindingConte xt(data).EndCur rentEdit()
I'll try that. Thanks.
>
>For some reason the result of the EXISTS function seems to come back as
an integer in the Dataset.

The EXISTS operator returns a value of bit. In .NET, the corresponding
type
is Boolean. If a data column is of type Boolean, DataGridView will
generate
a DataGridViewChe ckBoxColumn for this data column.

Is the DataTable strong-typed in your application?
No.
If so, you may open the
DataSet in the designer and select the column of the DataTable and check
the column's type in the Properties window. If not, you need to set a
break
point in your code and press F5 to run the application. When the
application enters into break mode, you can check the type of the
DataTable's column.
I think I have done this, and IIRC it was returning Int16. I'll check this
again tomorrow.
>
Thanks for your help.
Phil.
Jun 27 '08 #10

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

Similar topics

3
1687
by: Wanda | last post by:
I am using vb.net and have a bounded datagrid by using SQLDataAdaptor and SQLDataSet, it does show the data when it is first loaded. But when I change the data on the datagrid, it doesn't update the database, even I use AcceptChanges... What am I missing? What I am expecting is it should update the database automatically without doing it manually with the code. Please help!!!!
3
11776
by: thomasp | last post by:
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
1
7729
by: JeremyGrand | last post by:
I've read what's available here, but can't seem to make this work right. I'm experimenting with components on a form, although I'd rather create the pieces & assemble them in code, but that's another issue entirely. I have a table in sql2k with an autoincrement column as primary index. It also has a changeDate column with a trigger that updates to current datetime when any column other than itself is changed. Made a new form, followed...
2
5018
by: Ivan | last post by:
I have a class Foo which have two property. I have a thread that do some process and update class Foo int B. I have a datagridview on main form. this datagridview data source to this class Foo and column A binds to string A and column B binds to int B. When i start two threads, the datagridview able to show two rows and updated int B at run time. How? public class Foo { public Foo()
7
10068
by: John J. Hughes II | last post by:
I have a DataGridView with a TextBoxColumn. I setting the data source to a List<stringvalue in a static class. The list is filled from a background thread. So far all is fine and it works great, at least on my system. The reason I am doing this is some customers are pulling from VPN connections which are slow. This allows the list of rows in the data grid to appear a little quicker while the list which are not used as soon load in...
1
8763
by: MFayaz | last post by:
Hello! I have to refresh datagridview when database update , IS there any way to solution that my datagridview auto refresh when any user update database. Thanks in Advance
7
2406
by: BONES7714 | last post by:
Hello, This is my first post to any sort of forum although I've used them to learn the very little Access/VBA that I know so please forgive my ignorance. I work for the National Guard as Combat Medic and I've been tasked with created a DB to track the location of other soldiers medical records and other various infomation. As such, I have a form where I can enter the barcode for a record into a textbox and have it added to a listbox and...
1
6453
by: bharathi228 | last post by:
hello sir, iam new to windows application.iam working with datagridview in vb.net .how to update the selected row in datagridview.any one help me with this.
0
8888
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
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9257
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
9174
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,...
0
9111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8096
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6011
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
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
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

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.