读书人

spread绑定了combobox的有关问题

发布时间: 2012-04-01 17:23:46 作者: rapoo

spread绑定了combobox的问题
大家好,有一个关于spread的问题。我在spread里面绑定了一个combobox,combobox里面有2个固定的值 1.是 2.否

表tab1如下
userId userName sexId yesNoFlg
0000001 Tom 男 1
0000002 Cat 男 2
0000003 Wil 男 2
0000004 Kim 男 1

查询sql如下
select userId,userName,sexId,yesNoFlg
from tab1
字段yesNoFlg对应这个spread绑定的combobox。

以上的查询在spread中显示应该显示为
0000001 Tom 男 1.是
0000002 Cat 男 2.否
0000003 Wil 男 2.否
0000004 Kim 男 1.是

如果该yesNoFlg=1,则combobox中的“1.是”被选中。如果该yesNoFlg=2,则combobox中的“2.否”被选中。应该怎么实现。具体代码应怎么写。谢谢。我写的代码,combobox总是选不上,不知道为什么。

[解决办法]
spread 是什么东西?

spread先不管它是什么
前提先让combobox里有值
private sub addCombobox
combobox.items.add("是")
combobox.items.add("否")
combobox.selectedIndex = -1
end sub
然后把查询出的结果集放到一个DataTable里
然后判断
If DataTable.Rows(i).Item("yesNoFlg") = 1 then
combobox.selectedIndex = 0
elseif DataTable.Rows(i).Item("yesNoFlg") = 2 then
combobox.selectedIndex = 1
end if

[解决办法]
这个控件是日本人开发的好像。
spread里头的cell无法向combobox进行类型转换的。比较麻烦

现在采取的做法比较麻烦,只针对只有一两个combobox的情况
编辑designer文件。
修改将下面的声明暴露出来
FarPoint.Win.Spread.CellType.ComboBoxCellType comboBoxCellType1 = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
成为 private FarPoint.Win.Spread.CellType.ComboBoxCellType comboBoxCellType1;这样的格式。

然后就可以在cs代码中调用到对应的comboBoxCellType1 。
期待更简单的做法
[解决办法]

VB.NET code
            Dim objStyleInfo As New StyleInfo            Dim objCellType As New ComboBoxCellType            Dim intI As Integer            Dim strName() As String            Dim strCode() As String            ReDim strName(2)            ReDim strCode(2)            strCode(0)="1"            strCode(1)="2"            strName(0)="是"            strName(1)="否"            objCellType.ItemData = strCode            objCellType.Items = strName            objCellType.EditorValue = CellType.EditorValue.ItemData            With objStyleInfo                .VerticalAlignment = CellVerticalAlignment.Center                .HorizontalAlignment = CellHorizontalAlignment.Left                .CellType = objCellType                .Locked = false            End With            fpSpread.ActiveSheet.SetStyleInfo(-1, enumContSpreadCol.3,objStyleInfo)            '最后别忘了绑定               fpSpread.ActiveSheet.Columns(3).DataField = Me.Dataset.dtData.yesNoFlgColumn.ColumnName               fpSpread.ActiveSheet.DataSource = dtData 

读书人网 >VB Dotnet

热点推荐