更改取消后绑定显示丢失 [英] Bindings appear lost after changes are cancelled

查看:49
本文介绍了更改取消后绑定显示丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部


我正在使用DataGrid和一个由多个文本组成的表单,

复选框,组合框控件,都绑定到同一个数据表。当我在新字样上点击

时按钮,我创建一个新行,使其成为当前行,并允许用户在表单中进行更改。如果用户希望取消,他们可以点击取消更改。按钮。这是我的问题开始的地方。

点击取消更改按钮后,表单上的绑定会显示为

永久丢失,直到我关闭并重新打开表单。我已经附加了

New和Cancel按钮的相关部分单击Event例程作为

以及绑定初始化的代表部分。请注意,

我只在表单启动时绑定控件。


有谁能告诉我这里做错了什么?


TIA

Ron L


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

System .EventArgs)_

处理_btnNew.Click

....

''在数据表中创建一个新行并更改List Tab''s
过滤器,以便新行是所选项目

Dim dt As DataTable = CType(_ppdctlr.ListGrid.DataSource,DataTable)

Dim dr As DataRow = dt.NewRow

dr.Item(" PPDID")=" NewPPD"

dt.Rows.Add(dr)

CType(cm.List,DataView).RowFilter =" PPDID =''NewPPD''"

....

End Sub $ />

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

System.EventArgs)_

句柄_btnCancel 。点击

Dim cm作为CurrencyManager

Dim drv,newRow As DataRowView

Dim permLevel As Integer


Dim dt As DataTable = CType(_ppdctlr.ListGrid.DataSource,DataTable)

dt.RejectChanges()

''重置之前选择的ID。

_listCtlr.SetCurrentRow(_listSelectedID)

drv = CType(cm.List,

DataView).Item(_ppdctlr.ListGrid.CurrentRowIndex)

permLevel = PermissionLevel(drv)

。 ...

End Sub


Private Sub BindUserControls()

Dim dt As DataTable = _ppdctlr.ListGrid.DataSource


_txtPPDID.DataBindings.Add(" text",dt," PPDID")

_txtGlobalID.DataBindings.Add(" text",dt," ; GlobalID")

_txtDuplicateOf.DataBindings.Add(" text",dt," DuplicateOf")

_txtCPRRequestSubmitted.DataBindings.Add(" text",dt ,

" CPRRequestedDate")

_cbCPRRequired.DataBindings.Add(&qu ot;选中",dt," CPRRequired")

_cbDPRRequired.DataBindings.Add(" Checked",dt," DPRRequired")

_txtTitle.DataBindings。添加(" text",dt," Title")

_txtModDate.DataBindings.Add(" text",dt," ModifiedDate")

_cboType。 DataBindings.Add(" text",dt," Type")

_cboProblemArea.DataBindings.Add(" text",dt," ProblemArea")

....

End Sub

解决方案

Ron,


我没有看到直接的错误,但这是否有效。

Private Sub CancelChanges(ByVal sender As System.Object,ByVal e As
System.EventArgs)_
处理_btnCancel.Click
Dim cm作为CurrencyManager
Dim drv,newRow As DataRowView
Dim permLevel As Integer

Dim d t作为DataTable = CType(_ppdctlr.ListGrid.DataSource,
DataTable)
dt.RejectChanges()

''重置之前选择的ID。
_listCtlr.SetCurrentRow (_listSelectedID)
drv = CType(cm.List,
DataView).Item(_ppdctlr.ListGrid.CurrentRowIndex)




那个厘米(货币管理员)我只是一个地址,没有任何

参考。


Cor


Cor


感谢您的回复。我的坏,对于cm的分配是在我为了清晰度而切割的代码中。

。以下行是在我的代码之后的

dt.RejectChanges行:


cm =

CType(_ppdctlr.ListGrid .BindingContext(CType(_ppdc tlr.ListGrid.DataSource,

DataTable)),CurrencyManager)


基本上,我的问题似乎是绑定丢失了当

更改被取消时。


Ron L

" Cor Ligthert [MVP]" <无************ @ planet.nl>在消息中写道

新闻:Ow ************** @ TK2MSFTNGP14.phx.gbl ...

Ron,
我没有看到直接的错误,但这是否有效。

Private Sub CancelChanges(ByVal sender As System.Object,ByVal e As
System.EventArgs)_
句柄_btnCancel.Click
Dim cm作为CurrencyManager
Dim drv,newRow As DataRowView
Dim permLevel As Integer

Dim dt As DataTable = CType(_ppdctlr.ListGrid.DataSource,
DataTable)
dt.RejectChanges()

''重置先前选择的ID。
_listCtlr.SetCurrentRow(_listSelectedID )
drv = CType(cm.List,
DataView).Item(_ppdctlr.ListGrid.CurrentRowIndex)



那cm(currencymanager只是我的一个地址)没有任何
参考的意见)。

Cor






" Ron L" < RO ** @ bogus.Address.com>在留言中写道

news:es ************** @ TK2MSFTNGP14.phx.gbl ...

全部

我正在使用DataGrid和一个由许多文本,
复选框,组合框控件组成的表单,所有这些都绑定到同一个数据表。当我点击我的新时按钮,我创建一个新行,使其成为当前行,并允许用户在表单中进行更改。如果用户希望取消,他们可以点击取消更改。按钮。这是我的问题开始的地方。单击取消更改按钮后,表单上的绑定将永久丢失,直到我关闭并重新打开表单。
我已附加新建和取消按钮的相关部分单击<事件例程以及绑定
初始化的代表性部分。请注意,我只在表单启动时绑定控件。

任何人都可以告诉我这里做错了什么?


您是否已经为绑定的字段设置了默认值

CheckBox,CheckBox无法处理空值(常见于新行)和可能

使绑定崩溃,例如:


dt.Columns(" DPRRequired")。DefaultValue = false

dt .Columns(" CPRRequired")。DefaultValue = false


相反,您可以在创建

新行(dt后)时设置默认值。在你将它添加到Rows集合之前,*但是*。


我知道你没有使用CurrencyManager.AddNew但问题是

CheckBox是此处描述:
http:/ /support.microsoft.com/default...b;en-us;326440

hth,

问候

< TIA
Ron L
私人子BtnNew_Click(ByVal发送者As System.Object,ByVal e As
System.EventArgs )_
句柄_btnNew.Click
...
''在数据表中创建一个新行并更改List Tab'的
过滤器,以便新行是所选项目
Dim dt As DataTable = CType(_ppdctlr.ListGrid.DataSource,
DataTable)
Dim dr As DataRow = dt.NewRow
dr.Item(" PPDID" )=" NewPPD"
dt.Rows.Add(dr)
CType(cm.List,DataView).RowFilter =" PPDID =''NewPPD''"
.. 。
End Sub

Private Sub CancelChanges(ByVal sender As System.Object,ByVal e As
System.EventArgs)_
句柄_btnCancel.Click
Dim cm作为CurrencyManager
Dim drv,newRow As DataRowView
Dim permLevel As Integer

Dim dt As DataTable = CType(_ppdctlr.ListGrid.DataSource,
DataTable)
dt.RejectChanges()

''重置之前选择的ID。
_listCtlr.SetCurrentRow(_listSelectedID)
drv = CType(cm.List,
DataView).Item(_ppdctlr.ListGrid.CurrentRowIndex)
permLevel = PermissionLevel(drv)
...
End Sub

Private Sub BindUserControls()
Dim dt As DataTable = _ppdctlr.ListGrid.DataSource
<
_txtDuplicateOf.DataBindings .Add(" text",dt," DuplicateOf")
_txtCPRRequestSubmitted.DataBindings.Add(" text",dt,
" CPRRequestedDate")
_cbCPRRequired.DataBindings.Add (" Checked",dt," CPRRequired")
_cbDPRRequired.DataBindings.Add(" Checked",dt," DPRRequired")
_txtTitle.DataBindings.Add(" text" ;,dt," Title")
_txtModDate.DataBindings.Add(" text",dt," ModifiedDate")
_cboType.DataBindings.Add(" text",dt,"输入)
_cboProblemArea.DataBindings.Add(" text",dt," ProblemArea")
...
End Sub



All

I am working with a DataGrid and a form consisting of a number of text,
checkbox, combobox controls, all bound to the same datatable. When I click
on my "New" button, I create a new row, make it the current row, and allow
the user to make changes in the form. If the user desires to cancel, they
can click the "Cancel Changes" button. Here is where my problems start.
Once the Cancel Changes button is clicked, the bindings on the form appear
to be permanently lost until I close and re-open the form. I have attached
the relevant portions of the New and Cancel button Click Event routines as
well as a representative portion of the binding initializations. Note that
I only bind the controls at form startup.

Can anyone tell me what I am doing wrong here?

TIA
Ron L

Private Sub BtnNew_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles _btnNew.Click
....
'' Create a new row in the data table and change the List Tab''s
filter so that the new row is the selected item
Dim dt As DataTable = CType(_ppdctlr.ListGrid.DataSource, DataTable)
Dim dr As DataRow = dt.NewRow
dr.Item("PPDID") = "NewPPD"
dt.Rows.Add(dr)
CType(cm.List, DataView).RowFilter = "PPDID = ''NewPPD''"
....
End Sub

Private Sub CancelChanges(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles _btnCancel.Click
Dim cm As CurrencyManager
Dim drv, newRow As DataRowView
Dim permLevel As Integer

Dim dt As DataTable = CType(_ppdctlr.ListGrid.DataSource, DataTable)
dt.RejectChanges()
'' reset the previously selected ID.
_listCtlr.SetCurrentRow(_listSelectedID)
drv = CType(cm.List,
DataView).Item(_ppdctlr.ListGrid.CurrentRowIndex)
permLevel = PermissionLevel(drv)
....
End Sub

Private Sub BindUserControls()
Dim dt As DataTable = _ppdctlr.ListGrid.DataSource

_txtPPDID.DataBindings.Add("text", dt, "PPDID")
_txtGlobalID.DataBindings.Add("text", dt, "GlobalID")
_txtDuplicateOf.DataBindings.Add("text", dt, "DuplicateOf")
_txtCPRRequestSubmitted.DataBindings.Add("text", dt,
"CPRRequestedDate")
_cbCPRRequired.DataBindings.Add("Checked", dt, "CPRRequired")
_cbDPRRequired.DataBindings.Add("Checked", dt, "DPRRequired")
_txtTitle.DataBindings.Add("text", dt, "Title")
_txtModDate.DataBindings.Add("text", dt, "ModifiedDate")
_cboType.DataBindings.Add("text", dt, "Type")
_cboProblemArea.DataBindings.Add("text", dt, "ProblemArea")
....
End Sub

解决方案

Ron,

I don''t see direct the error, however does this work.

Private Sub CancelChanges(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles _btnCancel.Click
Dim cm As CurrencyManager
Dim drv, newRow As DataRowView
Dim permLevel As Integer

Dim dt As DataTable = CType(_ppdctlr.ListGrid.DataSource,
DataTable)
dt.RejectChanges()
'' reset the previously selected ID.
_listCtlr.SetCurrentRow(_listSelectedID)
drv = CType(cm.List,
DataView).Item(_ppdctlr.ListGrid.CurrentRowIndex)



That cm (currencymanager is just an address in my opinon without any
reference in it).

Cor


Cor

Thanks for the response. My Bad, the assignment to cm was in the code I cut
for clarity. The following line is in my code just after the
dt.RejectChanges line:

cm =
CType(_ppdctlr.ListGrid.BindingContext(CType(_ppdc tlr.ListGrid.DataSource,
DataTable)), CurrencyManager)

Basically, my problem appears to be that the bindings are lost when the
changes are cancelled.

Ron L
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Ow**************@TK2MSFTNGP14.phx.gbl...

Ron,

I don''t see direct the error, however does this work.

Private Sub CancelChanges(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles _btnCancel.Click
Dim cm As CurrencyManager
Dim drv, newRow As DataRowView
Dim permLevel As Integer

Dim dt As DataTable = CType(_ppdctlr.ListGrid.DataSource,
DataTable)
dt.RejectChanges()
'' reset the previously selected ID.
_listCtlr.SetCurrentRow(_listSelectedID)
drv = CType(cm.List,
DataView).Item(_ppdctlr.ListGrid.CurrentRowIndex)



That cm (currencymanager is just an address in my opinon without any
reference in it).

Cor



Hi,

"Ron L" <ro**@bogus.Address.com> wrote in message
news:es**************@TK2MSFTNGP14.phx.gbl...

All

I am working with a DataGrid and a form consisting of a number of text,
checkbox, combobox controls, all bound to the same datatable. When I
click on my "New" button, I create a new row, make it the current row, and
allow the user to make changes in the form. If the user desires to
cancel, they can click the "Cancel Changes" button. Here is where my
problems start. Once the Cancel Changes button is clicked, the bindings on
the form appear to be permanently lost until I close and re-open the form.
I have attached the relevant portions of the New and Cancel button Click
Event routines as well as a representative portion of the binding
initializations. Note that I only bind the controls at form startup.

Can anyone tell me what I am doing wrong here?
Did you already set default values for the fields that are bound to
CheckBox, CheckBox can''t handle null values (common for new rows) and may
crash the binding, eg.:

dt.Columns( "DPRRequired").DefaultValue = false
dt.Columns( "CPRRequired").DefaultValue = false

Instead you could probely also set the default values after you create the
new row (dt.NewRow), *but* before you add it to the Rows collection.

I know you are not using CurrencyManager.AddNew but the problem with
CheckBox is described here:
http://support.microsoft.com/default...b;en-us;326440
hth,
greetings


TIA
Ron L

Private Sub BtnNew_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles _btnNew.Click
...
'' Create a new row in the data table and change the List Tab''s
filter so that the new row is the selected item
Dim dt As DataTable = CType(_ppdctlr.ListGrid.DataSource,
DataTable)
Dim dr As DataRow = dt.NewRow
dr.Item("PPDID") = "NewPPD"
dt.Rows.Add(dr)
CType(cm.List, DataView).RowFilter = "PPDID = ''NewPPD''"
...
End Sub

Private Sub CancelChanges(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles _btnCancel.Click
Dim cm As CurrencyManager
Dim drv, newRow As DataRowView
Dim permLevel As Integer

Dim dt As DataTable = CType(_ppdctlr.ListGrid.DataSource,
DataTable)
dt.RejectChanges()
'' reset the previously selected ID.
_listCtlr.SetCurrentRow(_listSelectedID)
drv = CType(cm.List,
DataView).Item(_ppdctlr.ListGrid.CurrentRowIndex)
permLevel = PermissionLevel(drv)
...
End Sub

Private Sub BindUserControls()
Dim dt As DataTable = _ppdctlr.ListGrid.DataSource

_txtPPDID.DataBindings.Add("text", dt, "PPDID")
_txtGlobalID.DataBindings.Add("text", dt, "GlobalID")
_txtDuplicateOf.DataBindings.Add("text", dt, "DuplicateOf")
_txtCPRRequestSubmitted.DataBindings.Add("text", dt,
"CPRRequestedDate")
_cbCPRRequired.DataBindings.Add("Checked", dt, "CPRRequired")
_cbDPRRequired.DataBindings.Add("Checked", dt, "DPRRequired")
_txtTitle.DataBindings.Add("text", dt, "Title")
_txtModDate.DataBindings.Add("text", dt, "ModifiedDate")
_cboType.DataBindings.Add("text", dt, "Type")
_cboProblemArea.DataBindings.Add("text", dt, "ProblemArea")
...
End Sub



这篇关于更改取消后绑定显示丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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