绑定列表不同步

编程入门 行业动态 更新时间:2024-10-24 18:23:00
本文介绍了绑定列表不同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

VS 2005 我有一类BindingList(T)用作查询的数据源 组合框。组合框用于查找采购订单的条款。 当我在Winform上实现它时,组合框不会与 基础数据同步,即条款描述没有显示条款 数字。 组合框确实在下拉框中显示描述,因此它们是 被填入绑定列表,他们只是不同步 基础数据。 任何人都可以看到是什么错了? 瑞克 **** combox盒就像这样连接*** cbTerms。 DisplayMember =" Name" cbTerms.ValueMember =" Num" Dim bs As LookupNVP = New LookupNVP(LookupNVP.listType。条款,fMain.conn) cbTerms.DataSource = bs cbTerms.DataBindings.Clear() cbTerms.DataBindings.Add(" SelectedValue",PObind," Termsnum") **** class fo r bindinglist **** Public Class LookupNVP 继承BindingList(of nvp) 公共枚举列表类型 条款 Shipvia 结束枚举 公共类nvp 私有_name为字符串 私有_num为整数 Public ReadOnly属性名称()为字符串 获取 返回_name 结束获取 结束物业 Public ReadOnly Property Num()作为整数 获取 返回_num 结束获取 结束物业 Private Sub New() End Sub Public Sub New(ByVal newValue As Integer,ByVal newName As String) _name = newName _num = newValue End Sub 结束班 Public Sub New(ByVal list as lis tType,ByVal conn As FbConnection) MyBase.New() Dim sql As String 选择案例列表 案例列表类型.Shipvia sql ="选择SHIPVIANUM,METHOD || ''[''|| SHIPVIANUM || '']''' _ & 来自SHIPVIA的方法订购 案例列表类型。条款 sql ="选择TERMSNUM,DESCRIPTION || ''[''|| TERMSNUM || '']''' _ & 来自TERMS排序说明 结束选择 如果sql什么都没有那么返回 Dim cmd As FbCommand = New FbCommand(sql,conn) ''Dim reader As FbDataReader 试试 conn.Open() 使用reader作为FbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) 虽然读者阅读 Me.Add(新nvp(reader.GetInt32(0),reader.GetString(1))) 结束时 reader.Close() 结束使用 最后 conn.Close() 结束尝试 End Sub 结束类

解决方案

覆盖LookupNVP类中的ToString方法。 那么当你发布你的代码时,如果你将它粘贴到记事本中,那么 将它复制并粘贴到你的帖子中,它会l保持其间距,并且更容易阅读。阅读越容易,有人就越有可能帮助你了。 Robin S. ---- ----------------------- " Rick" < Ri ** @ LakeValleySeed写信息 新闻:%2 **************** @ TK2MSFTNGP04.phx.gbl ...

VS 2005 我有一类BindingList(T)用作查询的数据源 组合框。组合框用于查找采购订单的条款。 当我在Winform上实现它时,组合框不会与 基础数据同步,即条款描述没有显示条款 数字。 组合框确实在下拉框中显示描述,因此它们是 被填入绑定列表,他们只是不同步 基础数据。 任何人都可以看到是什么错了? 瑞克 **** combox盒就像这样连接*** cbTerms。 DisplayMember =" Name" cbTerms.ValueMember =" Num" Dim bs As LookupNVP = New LookupNVP(LookupNVP.listType。条款,fMain.conn) cbTerms.DataSource = bs cbTerms.DataBindings.Clear() cbTerms.DataBindings.Add(" SelectedValue",PObind," Termsnum") ****类为bi ndinglist **** Public Class LookupNVP 继承BindingList(of nvp) 公共枚举列表类型 条款 Shipvia 结束枚举 公共类nvp 私有_name为字符串 私有_num为整数 Public ReadOnly属性名称()为字符串 获取 返回_name 结束获取 结束物业 Public ReadOnly Property Num()as Integer 获取 返回_num 结束获取 结束物业 Private Sub New() End Sub Public Sub New(ByVal newValue As Integer,ByVal newName As String) _name = newName _num = newValue End Sub 结束类 Public Sub New(ByVal list as listType,ByVal conn As FbConnecti on) MyBase.New() Dim sql As String 选择案例列表 案例listType.Shipvia sql ="选择SHIPVIANUM,METHOD || ''[''|| SHIPVIANUM || '']''' _ & 来自SHIPVIA的方法订购 案例列表类型。条款 sql ="选择TERMSNUM,DESCRIPTION || ''[''|| TERMSNUM || '']''' _ & 来自TERMS排序说明 结束选择 如果sql什么都没有那么返回 Dim cmd As FbCommand = New FbCommand(sql,conn) ''Dim reader As FbDataReader 试试 conn.Open() 使用reader作为FbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) 虽然读者阅读 Me.Add(新nvp(reader.GetInt32(0),reader.GetString(1))) 结束时 reader.Close() 结束使用 最后 conn.Close() 结束尝试 End Sub 结束班

感谢笔记本提示。 我覆盖了ToString方法,但仍然没有快乐。另外是******** 以下。 我做错了什么? 公共类LookupNVP 继承BindingList(of nvp) Public Enum listType 条款 Shipvia 结束枚举 公共类nvp 私有_name为字符串 私有_num为整数 Public ReadOnly属性名称()为字符串 获取 返回_name 结束获取 结束物业 公共只读物业数量()为整数 获取 返回_num 结束获取 结束物业 私人子新() 结束子 Public Sub New(ByVal newValue As Integer,ByVal newName As String) _name = newName _num = newValue End Sub ''************************************* ******* Public Overrides Function ToString()As String 返回我。姓名 结束功能 ''************************* ******************** 结束班级 Public Sub New( ByVal list作为listType,ByVal conn As FbConnection) MyBase.New() Dim sql As String 选择案例列表 Case listType.Shipvia sql ="选择SHIPVIANUM,METHOD || ''[''|| SHIPVIANUM || '']''" _ & 按SHIPVIA方式订购 案例清单类型。条款 sql ="选择TERMSNUM,DESCRIPTION || ''[''|| TERMSNUM || '']''" _ & 来自TERMS排序说明 结束选择 如果sql什么都没有那么返回 Dim cmd作为FbCommand = New FbCommand(sql,conn) ''Dim reader As FbDataReader 试试 conn.Open() 使用reader作为FbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) 虽然reader.Read Me.Add(New nvp(reader.GetInt32(0),reader.GetString(1))) 结束时 reader.Close() 结束使用 最后 conn.Close() 结束尝试 End Sub 结束班 " RobinS" < Ro **** @ NoSpam.yah.nonewrote in message news:6f ************************ ******@comcast。 ..

覆盖LookupNVP类中的ToString方法。 顺便提一下,当你发布代码时,如果你将它粘贴到记事本中,然后将复制并粘贴到你的帖子中,它将保留其间距,并且更容易阅读。阅读越容易,有人就越有可能帮助你。 Robin S.

将你的nvp类移出lookupNvp类。 Public Class LookupNVP 继承BindingList(of nvp) .... 结束班 公共舱NVP .... (ToString在这里) 结束类 将数据库的读数放在LookupNVP中,并将每个NVP对象添加到 你的清单。 Robin S. ----------------- ---------- < Rick" < Ri ** @ LakeValleySeed写信息 news:eQ ************** @ TK2MSFTNGP03.phx.gbl ... 感谢笔记本提示。 我超越了ToString方法,但仍然没有快乐。下面是 ********。 我做错了什么? 公共类LookupNVP 继承BindingList(of nvp) Public Enum listType 条款 Shipvia 结束枚举 公共类nvp 私有_name为字符串 私有_num为整数 Public ReadOnly属性名称()为字符串 获取 返回_name 结束获取 结束物业 公共只读物业数量()为整数 获取 返回_num 结束获取 结束物业 私人子新() 结束子 Public Sub New(ByVal newValue As Integer,ByVal newName As String) _name = newName _num = newValue 结束子 ''************************ ******************** Public Overrides Function ToString()As String Return Me.Name 结束功能 ''**************************** ***************** 结束班 Public Sub New(ByVal list As listType,ByVal conn As FbConnection) MyBase.New() Dim sql As String 选择案例列表 案例listType.Shipvia sql ="选择SHIPVIANUM,METHOD || ''[''|| SHIPVIANUM || '']''" _ & 按SHIPVIA方式订购 案例清单类型。条款 sql ="选择TERMSNUM,DESCRIPTION || ''[''|| TERMSNUM || '']''" _ & 来自TERMS排序说明 结束选择 如果sql什么都没有那么返回 Dim cmd作为FbCommand = New FbCommand(sql,conn) ''Dim reader As FbDataReader 试试 conn.Open() 使用reader作为FbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) 虽然reader.Read Me.Add(New nvp(reader.GetInt32(0), reader.GetString(1))) 结束时 reader.Close() 结束使用 最后 conn.Close() 结束尝试 End Sub 结束班级 RobinS < Ro **** @ NoSpam.yah.nonewrote in message news:6f ************************ ******@comcast。 ..

>覆盖LookupNVP类中的ToString方法。 顺便说一下,当你发布你的代码时,如果你粘贴了它进入记事本,然后将其复制并粘贴到您的帖子中,它将保留其间距,并且更易于阅读。阅读越容易,人们就越有可能帮助你。 Robin S.

VS 2005 I have a class of BindingList(of T) to use as a datasource for a lookup combobox. The combobox is to lookup the Terms for a Purchase Order. When I implement this on my Winform, the combobox does not synch with the underlying data, i.e. the Terms description does not show for the terms number. The combobox does show the Descriptions in the drop-down box, so they are being filled into the binding list, they just don''t synch with the underlying data. Can anyone see what is wrong? Rick **** combox box is connected like this *** cbTerms.DisplayMember = "Name" cbTerms.ValueMember = "Num" Dim bs As LookupNVP = New LookupNVP(LookupNVP.listType.Terms, fMain.conn) cbTerms.DataSource = bs cbTerms.DataBindings.Clear() cbTerms.DataBindings.Add("SelectedValue", PObind, "Termsnum") **** class for bindinglist **** Public Class LookupNVP Inherits BindingList(Of nvp) Public Enum listType Terms Shipvia End Enum Public Class nvp Private _name As String Private _num As Integer Public ReadOnly Property Name() As String Get Return _name End Get End Property Public ReadOnly Property Num() As Integer Get Return _num End Get End Property Private Sub New() End Sub Public Sub New(ByVal newValue As Integer, ByVal newName As String) _name = newName _num = newValue End Sub End Class Public Sub New(ByVal list As listType, ByVal conn As FbConnection) MyBase.New() Dim sql As String Select Case list Case listType.Shipvia sql = "Select SHIPVIANUM, METHOD || '' ['' || SHIPVIANUM || '']'' " _ & "from SHIPVIA order by METHOD" Case listType.Terms sql = "Select TERMSNUM, DESCRIPTION || '' ['' || TERMSNUM || '']'' " _ & "from TERMS order by DESCRIPTION" End Select If sql Is Nothing Then Return Dim cmd As FbCommand = New FbCommand(sql, conn) ''Dim reader As FbDataReader Try conn.Open() Using reader As FbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) While reader.Read Me.Add(New nvp(reader.GetInt32(0), reader.GetString(1))) End While reader.Close() End Using Finally conn.Close() End Try End Sub End Class

解决方案

Override the ToString method in your LookupNVP class. By the way, when you post your code, if you paste it into Notepad, then copy and paste it into your posting, it will retain its spacing, and be easier to read. The easier it is to read, the more likely someone will help you. Robin S. --------------------------- "Rick" <Ri**@LakeValleySeedwrote in message news:%2****************@TK2MSFTNGP04.phx.gbl...

VS 2005 I have a class of BindingList(of T) to use as a datasource for a lookup combobox. The combobox is to lookup the Terms for a Purchase Order. When I implement this on my Winform, the combobox does not synch with the underlying data, i.e. the Terms description does not show for the terms number. The combobox does show the Descriptions in the drop-down box, so they are being filled into the binding list, they just don''t synch with the underlying data. Can anyone see what is wrong? Rick **** combox box is connected like this *** cbTerms.DisplayMember = "Name" cbTerms.ValueMember = "Num" Dim bs As LookupNVP = New LookupNVP(LookupNVP.listType.Terms, fMain.conn) cbTerms.DataSource = bs cbTerms.DataBindings.Clear() cbTerms.DataBindings.Add("SelectedValue", PObind, "Termsnum") **** class for bindinglist **** Public Class LookupNVP Inherits BindingList(Of nvp) Public Enum listType Terms Shipvia End Enum Public Class nvp Private _name As String Private _num As Integer Public ReadOnly Property Name() As String Get Return _name End Get End Property Public ReadOnly Property Num() As Integer Get Return _num End Get End Property Private Sub New() End Sub Public Sub New(ByVal newValue As Integer, ByVal newName As String) _name = newName _num = newValue End Sub End Class Public Sub New(ByVal list As listType, ByVal conn As FbConnection) MyBase.New() Dim sql As String Select Case list Case listType.Shipvia sql = "Select SHIPVIANUM, METHOD || '' ['' || SHIPVIANUM || '']'' " _ & "from SHIPVIA order by METHOD" Case listType.Terms sql = "Select TERMSNUM, DESCRIPTION || '' ['' || TERMSNUM || '']'' " _ & "from TERMS order by DESCRIPTION" End Select If sql Is Nothing Then Return Dim cmd As FbCommand = New FbCommand(sql, conn) ''Dim reader As FbDataReader Try conn.Open() Using reader As FbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) While reader.Read Me.Add(New nvp(reader.GetInt32(0), reader.GetString(1))) End While reader.Close() End Using Finally conn.Close() End Try End Sub End Class

Thanks for the notebook tip. I overrode the ToString method, but still no joy. The addition is ******** below. What did I do wrong? Public Class LookupNVP Inherits BindingList(Of nvp) Public Enum listType Terms Shipvia End Enum Public Class nvp Private _name As String Private _num As Integer Public ReadOnly Property Name() As String Get Return _name End Get End Property Public ReadOnly Property Num() As Integer Get Return _num End Get End Property Private Sub New() End Sub Public Sub New(ByVal newValue As Integer, ByVal newName As String) _name = newName _num = newValue End Sub ''******************************************** Public Overrides Function ToString() As String Return Me.Name End Function ''********************************************* End Class Public Sub New(ByVal list As listType, ByVal conn As FbConnection) MyBase.New() Dim sql As String Select Case list Case listType.Shipvia sql = "Select SHIPVIANUM, METHOD || '' ['' || SHIPVIANUM || '']'' " _ & "from SHIPVIA order by METHOD" Case listType.Terms sql = "Select TERMSNUM, DESCRIPTION || '' ['' || TERMSNUM || '']'' " _ & "from TERMS order by DESCRIPTION" End Select If sql Is Nothing Then Return Dim cmd As FbCommand = New FbCommand(sql, conn) ''Dim reader As FbDataReader Try conn.Open() Using reader As FbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) While reader.Read Me.Add(New nvp(reader.GetInt32(0), reader.GetString(1))) End While reader.Close() End Using Finally conn.Close() End Try End Sub End Class "RobinS" <Ro****@NoSpam.yah.nonewrote in message news:6f******************************@comcast. ..

Override the ToString method in your LookupNVP class. By the way, when you post your code, if you paste it into Notepad, then copy and paste it into your posting, it will retain its spacing, and be easier to read. The easier it is to read, the more likely someone will help you. Robin S.

Move your nvp class out of your lookupNvp class. Public Class LookupNVP Inherits BindingList(of nvp) .... End Class Public Class NVP .... (ToString goes here) End Class Put the reading of the database in LookupNVP, and add each NVP object to your list. Robin S. --------------------------- "Rick" <Ri**@LakeValleySeedwrote in message news:eQ**************@TK2MSFTNGP03.phx.gbl...

Thanks for the notebook tip. I overrode the ToString method, but still no joy. The addition is ******** below. What did I do wrong? Public Class LookupNVP Inherits BindingList(Of nvp) Public Enum listType Terms Shipvia End Enum Public Class nvp Private _name As String Private _num As Integer Public ReadOnly Property Name() As String Get Return _name End Get End Property Public ReadOnly Property Num() As Integer Get Return _num End Get End Property Private Sub New() End Sub Public Sub New(ByVal newValue As Integer, ByVal newName As String) _name = newName _num = newValue End Sub ''******************************************** Public Overrides Function ToString() As String Return Me.Name End Function ''********************************************* End Class Public Sub New(ByVal list As listType, ByVal conn As FbConnection) MyBase.New() Dim sql As String Select Case list Case listType.Shipvia sql = "Select SHIPVIANUM, METHOD || '' ['' || SHIPVIANUM || '']'' " _ & "from SHIPVIA order by METHOD" Case listType.Terms sql = "Select TERMSNUM, DESCRIPTION || '' ['' || TERMSNUM || '']'' " _ & "from TERMS order by DESCRIPTION" End Select If sql Is Nothing Then Return Dim cmd As FbCommand = New FbCommand(sql, conn) ''Dim reader As FbDataReader Try conn.Open() Using reader As FbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) While reader.Read Me.Add(New nvp(reader.GetInt32(0), reader.GetString(1))) End While reader.Close() End Using Finally conn.Close() End Try End Sub End Class "RobinS" <Ro****@NoSpam.yah.nonewrote in message news:6f******************************@comcast. ..

>Override the ToString method in your LookupNVP class.By the way, when you post your code, if you paste it into Notepad, thencopy and paste it into your posting, it will retain its spacing, and beeasier to read. The easier it is to read, the more likely someone willhelp you.Robin S.

更多推荐

绑定列表不同步

本文发布于:2023-10-26 19:07:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531083.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   不同步   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!