Datagridview不会更新当前行值 [英] Datagridview doesn't update current row values

查看:56
本文介绍了Datagridview不会更新当前行值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VB2008

我有一个DataSeridView,MultiSelect = True,

SelectionMode = FullRowSelect。其中一列是复选框列。我有

a函数遍历所有选定的行并设置

此列的值。


For Each row In DataGridView1.SelectedRows

row.Cells(" MyCheckboxColumn")。值= False

下一页


这似乎差不多了,但我注意到有时它不会更新

第一个或最后一个选定的行。经过调查,似乎更新了

值,但如果该行恰好是当前行,则更改为

,直到当前流量改变为止。我已经设法绕过这个问题,通过在我做出更改后设置CurrentCell = Nothing来解决这个问题,

但是这有清除选择的不良副作用。 />

有什么建议吗?


TIA

菲尔。

VB2008
I have a DataGridView with MultiSelect = True and
SelectionMode=FullRowSelect. 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.SelectedRows
row.Cells("MyCheckboxColumn").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.

推荐答案

嗨Phil,


我根据您的描述进行了测试,但没有重现

问题在我身边在我的测试应用程序中,DataGridView中的所有选定行都会立即更新




我在VS2008中创建一个WinForm应用程序项目并添加一个DataGridView和

a Form1上的按钮。我在

DataGridView中添加了一个DataGridViewCheckBoxColumn。以下是Form1.vb中的代码:


Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load

Me.DataGridView1.SelectionMode =

DataGridViewSelectionMode.FullRowSelect

Me.DataGridView1 .RowCount = 10

for i As Integer = 0 to 9

Me.DataGridView1.Rows(i).Cells(0).Value = True

下一页

结束子


Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As

系统。 EventArgs)处理Button1.Click

For Each row As DataGridViewRow In Me.DataGridView1.SelectedRows

row.Cells(0).Value = False

下一页

结束次级

结束班级


构建并运行应用程序。使用

鼠标在DataGridView中选择一些行,然后单击按钮,所有选中的行立即更新。

您的代码与我的代码有什么区别吗?


此致,

Linda Liu

微软在线社区支持


让我们的客户满意是我们的# 1优先。我们欢迎您的意见和

有关我们如何改进我们为您提供的支持的建议。请

随时让我的经理知道您对服务水平的看法

提供。您可以直接向我的经理发送反馈:
ms****@microsoft.com


========================================== ========

通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx

======================================== ==========

此帖子按原样提供。没有保证,也没有赋予任何权利。
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 DataGridViewCheckBoxColumn in the
DataGridView. The following is the code in the Form1.vb:

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.DataGridView1.SelectionMode =
DataGridViewSelectionMode.FullRowSelect
Me.DataGridView1.RowCount = 10
For i As Integer = 0 To 9
Me.DataGridView1.Rows(i).Cells(0).Value = True
Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
For Each row As DataGridViewRow In Me.DataGridView1.SelectedRows
row.Cells(0).Value = 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****@microsoft.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.




Linda Liu [MSFT]" < v - **** @ online.microsoft.com写信息

新闻:Fj ************** @ TK2MSFTNGHUB02.phx.gbl ...

"Linda Liu[MSFT]" <v-****@online.microsoft.comwrote in message
news:Fj**************@TK2MSFTNGHUB02.phx.gbl...

嗨菲尔,


我根据您的描述进行了测试,但没有重现

问题在我身边。在我的测试应用程序中,DataGridView中的所有选定行都会立即更新


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.



感谢您查看此内容。我的datagridview是一个更大的应用程序的一部分,

所以与你的代码有很大的不同。我将尝试在一个较小的应用程序中重现问题
。让我想到的主要事情是:b $ b不同的是我的数据是从数据源填充的(OleDb -

access / jet)。我不确定这是否相关。


菲尔。

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.




" Linda Liu [MSFT]" < v - **** @ online.microsoft.com写信息

新闻:Fj ************** @ TK2MSFTNGHUB02.phx.gbl ...

"Linda Liu[MSFT]" <v-****@online.microsoft.comwrote in message
news:Fj**************@TK2MSFTNGHUB02.phx.gbl...

嗨菲尔,


我根据您的描述进行了测试,但没有重现

问题在我身边。在我的测试应用程序中,DataGridView中的所有选定行都会立即更新


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.



确定。我已经设法调整你的代码来重现问题。

最初创建datagridview没有列并替换Form_Load

如下:


Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load


Me.DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect

Dim data As New DataTable

data.Columns.Add(" Column1",Type.GetType(" System.Int16" ))

我的整数= 0到9

data.Rows.Add(1)

下一页

Me.DataGridView1.DataSource = data


Dim col As New DataGridViewCheckBoxColumn

Me.DataGridView1.Columns.Add(col)

col.DataPropertyName =" Column1"


End Sub

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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Me.DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect

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

Me.DataGridView1.DataSource = data

Dim col As New DataGridViewCheckBoxColumn
Me.DataGridView1.Columns.Add(col)
col.DataPropertyName = "Column1"

End Sub


这篇关于Datagridview不会更新当前行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆