TechTalkz.com Logo Ask the Expert

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > VB.NET

Notices

Datagrid not automatically updating Datatable

VB.NET


Reply
 
Thread Tools Display Modes
Old 07-12-2007, 07:11 PM   #1
Chet
Guest
 
Posts: n/a
Datagrid not automatically updating Datatable

I have a Datagrid that is bound to a Datatable at runtime. I allow the
user to select a number of rows using the mouse and then click a button
that says "check selected rows", which then cycles through the selected
rows and sets a check box field in the datagrid (and thus the databound
datatable) to checked/true. It works like this:

Dim cel As DataGridViewCheckBoxCell
For Each row In DataGrid.SelectedRows
cel = row.Cells(0)
cel.Value = True
Next

I then have a property / function I expose that should show me the
number of currently checked rows. It looks like this:

Public ReadOnly Property CheckedRowCount() As Integer
Get
Dim v As DataView = New DataView(DataTable)
v.RowFilter = "[Selected]=true"
Return v.Count
End Get
End Property

When I select a set of rows and then click the button that runs the
first set of code, the property represented by the second set is always
ONE LESS than the number of rows selected. It's like it's not
automatically marking the last databound datarow as updated... is there
a way to force this? I've tried programmatically changing the
CurrentCell property of the datagrid to another row, and this works, but
it doesn't look good at all, and the user loses the cells they selected.

Any ideas?

P.S. I have also tried updating the underlying datarow instead of the
cell value, as in:

For Each row In DataGrid.SelectedRows
dim dr as datarow= CType(row.DataBoundItem, DataRowView).Row
dr(0)=true
Next
  Reply With Quote
Reply

Thread Tools
Display Modes



< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 05:05 PM.


vBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2010, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional