本文介绍了绑定列表不同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 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 结束类 解决方案 VS 2005I have a class of BindingList(of T) to use as a datasource for a lookupcombobox. The combobox is to lookup the Terms for a Purchase Order.When I implement this on my Winform, the combobox does not synch with theunderlying data, i.e. the Terms description does not show for the termsnumber.The combobox does show the Descriptions in the drop-down box, so they arebeing filled into the binding list, they just don''t synch with theunderlying 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 = bscbTerms.DataBindings.Clear()cbTerms.DataBindings.Add("SelectedValue", PObind, "Termsnum")**** class for bindinglist ****Public Class LookupNVPInherits BindingList(Of nvp)Public Enum listTypeTermsShipviaEnd EnumPublic Class nvpPrivate _name As StringPrivate _num As IntegerPublic ReadOnly Property Name() As StringGetReturn _nameEnd GetEnd PropertyPublic ReadOnly Property Num() As IntegerGetReturn _numEnd GetEnd PropertyPrivate Sub New()End SubPublic Sub New(ByVal newValue As Integer, ByVal newName As String)_name = newName_num = newValueEnd SubEnd ClassPublic Sub New(ByVal list As listType, ByVal conn As FbConnection)MyBase.New()Dim sql As StringSelect Case listCase listType.Shipviasql = "Select SHIPVIANUM, METHOD || '' ['' || SHIPVIANUM || '']'' " _& "from SHIPVIA order by METHOD"Case listType.Termssql = "Select TERMSNUM, DESCRIPTION || '' ['' || TERMSNUM || '']'' " _& "from TERMS order by DESCRIPTION"End SelectIf sql Is Nothing Then ReturnDim cmd As FbCommand = New FbCommand(sql, conn)''Dim reader As FbDataReaderTryconn.Open()Using reader As FbDataReader =cmd.ExecuteReader(CommandBehavior.CloseConnection)While reader.ReadMe.Add(New nvp(reader.GetInt32(0), reader.GetString(1)))End Whilereader.Close()End UsingFinallyconn.Close()End TryEnd SubEnd Class 解决方案 这篇关于绑定列表不同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-07 09:18