FpSpread控件的總結VB插件 2010-07-27 10:57:46 閱讀361 評論0 字號:大中小 訂閱
spread 中checkbox的用法
forpoint spreadsheet
列類(lèi)別選擇combo就可以了
spread的幫助文件中間搜索 CellType property, check box cells
//------------------------------------------------------
是這樣的,我的webform上放了一個(gè)FpSpread控件,我想把行頭變成checkbox樣式,我的方法是在后臺代碼中定義:
FarPoint.Web.Spread.CheckBoxCellType celltype = new FarPoint.Web.Spread.CheckBoxCellType();
然后將此type賦給行頭:
FpSpread1.ActiveSheetView.RowHeader.Cells[0,0].CellType=celltype;
我的問(wèn)題是:1.如果我想用一個(gè)Button控制當點(diǎn)擊Button時(shí),如果CheckBox是選中狀態(tài),則在該中顯示某某字符,但我不知道這種CheckBox的標識是什么,還有他的狀態(tài)為選中或沒(méi)選中返回值是什么?
2.還有其他方法嗎?比如我用
FpSpread1.ActiveSheetView.RowHeader.Cells[0,0].Text="<Input id=\"nihao\" checked type =\"CheckBox\" />"
遇到的困難和剛才一樣。
請問(wèn)怎么解決,多謝!
FpSpread1.columnsheader.cells(0,0).text="Check #"
//-------------------------------------------------------------
確定check所在的位置,然后直接判斷FpSpread1.Sheets(0).Cells(1,6).Value是否為1,為1就是選中狀態(tài)。我是這樣的。
Public Sub SetCOLCheck(spd As vaSpread, ByVal lCol1 As Long, ByVal lCol2 As Long, _
Optional ByVal IsCenter As Boolean = True)
With spd
.Col = lCol1
.Col2 = lCol2
.Row = -1
.BlockMode = True
.CellType = 10
.TypeHAlign = 0
.TypeCheckCenter = IsCenter
.BlockMode = False
End With
End Sub
我使用的是Spread,是這么填加的
//---------------------------------------------------------
1.BorderStyle:調整是否有邊框 默認為Fixed3D FixedSingle只有一條線(xiàn) 2.location x,y 調整位置
3.horizontalScrollBarPolicy 默認為Always橫向向滾共條始終存在,就是AsNeeded條數超過(guò)顯示就存在,否則不顯示,Never始終沒(méi)有滾動(dòng)條
4.verticalScrollBarPolicy 默認為Always縱向滾共條始終存在,就是AsNeeded條數超過(guò)顯示就存在,否則不顯示,Never始終沒(méi)有滾動(dòng)條
5.Enabled 是否可以編輯
點(diǎn)擊Sheets屬性旁的按鈕就會(huì )出現關(guān)于Sheets頁(yè)里面屬性的設置
1.selectionUnit 默認為Cell運行的時(shí)候,點(diǎn)擊單元格選中的只是一個(gè)單元 Column整列,Row整行
2.ColumnCount Spread表示數據的列數
3.RowCount Spread表示數據的行數
4.*OperationMode 主要是MultiSelect,SingleSelect兩種的區分SingleSelect只能選一行, MultiSelect可以擇多行。
5.rows和Column下的Resizable可以將列和行的大小固定為不可調整
AddColumns(Integer i, Integer j)添加列,i是起始位置,j是列數。
AddRows(Integer i, Integer j)添加列,i是起始位置,j是列數。
.AddSelection(I,j,k,m)添加選中的cell
.ClearRange AddSelection(I,j,k,m,true)清空Spread.還有很多常用的方法。就往Spread中放值的方法
1.創(chuàng )建對應的DataSource Me.FpSpread1_Sheet1().DataSource =objDs.Tables(0)
Me.FpSpread1_Sheet1().Columns(0).DataField = "id"
Me.FpSpread1_Sheet1().Columns(1).DataField = "name“
**Id,和name是從數據庫中查出來(lái)得數據結果集中數據表的字段名。
這樣從數據庫中查出的值就可放在相應的列上了。
2.也可單獨往單元格中放值
Me.FpSpread1_Sheet1.Cells(0, 0).Value() = “123”
*放值時(shí)需要注意的是FpSpread1_Sheet1的起始位置是(0,0)
如果只有4行4列的話(huà)是不存在(4,4)這樣的Cells的
Me.FpSpread1_Sheet1.ActiveRowIndex
可以取得選擇的行的索引值,從0開(kāi)始
FpSpread1_Sheet1.Cells(FpSpread1_Sheet1.ActiveRowIndex, 1)
可以取得選擇的行對應單元格的值。
Dim cellButtonType As New FarPoint.Win.Spread.CellType.ButtonCellType
cellButtonType.Text = "Detail"
Me.SpdYoteyi_Sheet1.ColumnHeader.Cells.Get(0, 3).BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(192, Byte))
With frm.SpdYoteyi.Sheets(0) .Columns.Get(0).ForeColor = System.Drawing.Color.Red
.Columns.Get(3).ForeColor = System.Drawing.Color.Blue
.SetText(0, 0, "eld001")
.SetText(0, 7, "2006/04/20")
.SetText(0, 9, "會(huì )社AAA")
// 動(dòng)態(tài)添加列。
.AddColumns(10, 1)
.Columns.Get(10).Label = "詳しい"
.Columns.Get(10).CellType = cellButtonType
End With
// 獲得當前選中行
.SpdYoteyi.ActiveSheet.ActiveRowIndex()
//-------------------------------------------------
關(guān)于spread的一些基本操作
對日軟件開(kāi)發(fā),經(jīng)常會(huì )用到spread控件。使用中積累了一些經(jīng)驗,自己總結一下。
1.spread的cell
在spread的設計界面里可以設置cell的各種屬性,和用慣的vb差不多。其實(shí)它的help寫(xiě)的挺詳細的,剛開(kāi)始日文不好看起來(lái)不方便,現在可以順利理解了。Cell可以是checkbox,文字,數字,時(shí)間等等類(lèi)型,可以只讀,可讀寫(xiě),還可以設置背景色,邊框等。和excel相像的。
2.Cell的讀寫(xiě)模式。
1. 只讀
① 全體只讀
With spdTEMP
.Col = 1
.Col2 = .MaxCols
.Row = 1
.Row2 = -1 '當spd里數據是0條時(shí),.MaxRows會(huì )出錯。用-1安全。
.Protect = True
.BlockMode = True
.Lock = True
.BlockMode = False
End With
②部分只讀,設置行和列就可以
With spdTEMP
.Col = 2
.Col2 = 5
.Row = 1
.Row2 = 8
.Protect = True
.BlockMode = True
.Lock = True
.BlockMode = False
End With
2.一般寫(xiě)模式和覆蓋寫(xiě)模式
一般寫(xiě)模式:.EditMode = True
覆蓋寫(xiě)模式:.EditModeReplace = True
區別在于 1)光標模式不同,一般寫(xiě)為單個(gè)鼠標入力光標,覆蓋寫(xiě)已有內容全選,替換輸入。
2)當輸入帶有小數的數字時(shí),覆蓋寫(xiě)會(huì )自動(dòng)跳到小數最末位,這可能是spread3.0在win2000下的bug吧。癥狀是第一遍輸入10.23時(shí)會(huì )變成1.03,第二遍輸入時(shí)就好了。試驗了很多次,最后不得已換成一般寫(xiě)模式。
3.spread的click事件
① 這是一段點(diǎn)擊每行第三列時(shí),自動(dòng)全行copy數據的例子。
Private Sub spdTMSR160_Click(ByVal Col As Long, ByVal Row As Long)
Dim temp As String
Dim i As Integer
If Row = 0 Then Exit Sub
If spdTMSR160.Lock = True Then Exit Sub
With spdTMSR160
.Col = 3
.Col2 = .MaxRows
.Row = Row
.Row2 = Row
If Col = 2 And .Value <> "" Then
If MsgBox("3月の予算金額を全ての月にコピーしてもよろしいですか?", vbQuestion + vbYesNo) = vbYes Then
.BlockMode = True
temp = .Value
For i = 1 To 11
.Col = .Col + 1: .Value = temp
Next
End If
End If
.BlockMode = False
End With
End Sub
② 這是一段有選擇按鈕的例子。選中時(shí)行變色,部分cell改變入力狀態(tài)。
Private Sub spdTMSR020_Click(ByVal Col As Long, ByVal Row As Long)
If Row = 0 Then Exit Sub
' If spdTMSR020.Lock = True Then Exit Sub
If Col >= 1 And Col <= 7 Then
With spdTMSR020
.Col = 1
.Col2 = .MaxCols
.Row = Row
.Row2 = Row
.Value = IIf(.Value = 0, 1, 0)
.BlockMode = True
If .Value = 0 Then
' If Row Mod 2 = 0 Then
' .BackColor = RGB(245, 236, 233)
' Else
.BackColor = RGB(255, 255, 255)
' End If
.Col = 8
.Col2 = 11
.Row = Row
.Row2 = Row
.Protect = True
.Lock = True
Else
.BackColor = RGB(128, 255, 128)
.Col = 8
.Col2 = 11
.Row = Row
.Row2 = Row
.Lock = False
.EditMode = True
End If
.BlockMode = False
End With
End If
End Sub
spread3.0的選擇按鈕很脆弱,一不小心小紅鉤不見(jiàn)了,事件卻沒(méi)有觸發(fā)。所以把邊上的固定列都設為可選擇狀態(tài)。
4.關(guān)于背景色的設置。
Backcolor 指定范圍,設置背景色
SetOddEvenRowColor,設置奇數,偶數行的顏色。
本來(lái)背景色是粉紅和白色相間的,但是單行變色判斷和全體變色中產(chǎn)生問(wèn)題,不得不改成全白的。
其根本原因是backcolor比SetOddEvenRowColor要強。Backcolor可以更改SetOddEvenRowColor設置的顏色,而SetOddEvenRowColor卻無(wú)法改變Backcolor設定的顏色。
而當數據很多時(shí),背景需要刷新時(shí),用backcolor一行一行判斷更改,畫(huà)面會(huì )產(chǎn)生劇烈顫抖….
//----------------------------------
序號屬性說(shuō)明
1.MaxRows = 10設置總行數為10行
2.MaxCols = 5設置總列數為5列
3.ColHeaderRows = 2表頭(列標題)行數為2
4.Row = SpreadHeader定位到表頭(列標題)
5.Row = -1定位到行頭(在設置列格式時(shí)使用)
6.ColWidth(1) = 16設置第1列的列寬為16
7.RowHeight(1) = 12設置第1行的行高為12
8.FontSize = 10"設置當前欄位的字體大小為10(如果.Row = -1,
則設置整列,下同)"
9.TypeHAlign = TypeHAlignRight設置文字水平對齊方式為右對齊
.TypeVAlign = TypeVAlignCenter設置文字垂直對齊方式為居中
10.CellType = CellTypeNumber設置為數字類(lèi)型
11.TypeNumberDecPlaces = 2設置小數位數
12.TypeNumberShowSep = True設置千位分隔
13.SetText 2, 3, "test"設置第2列第3行的文本為"test"
14.GetText 2, 3, MyText將第2列第3行的值賦給變量MyText
15.Row = 3定位到第3行
16.Col = 2定位到第2列
17.Text = "test"設置當前欄位的文本為"test"
18MyRow = .ActiveRow將當前行號賦值給變量MyRow
19.InsertRows 2, 1在第2行前插入1行
20.DeleteRows 2, 1"在第2行前刪除1行(如果Spread是通過(guò)設置數據源
取得數據的話(huà),則必須設置.DataSource = Nothing
才能刪除)"
21.InsertCols 2, 1在第2列前插入1列
22.DeleteCols 2, 1在第2列前刪除1列
23.AddCellSpan 3, 4, 2, 1從第3列第4行起合并單元格,跨度為2列1行
24.RowHeadersShow = False隱藏行標題
25.ColHeadersShow = False隱藏列標題
26.PrintMarginLeft = 1000打印時(shí)左邊距=1000(包括預覽)
27.PrintMarginTop = 1000打印時(shí)上邊距=1000(包括預覽)
28.OperationMode = OperationModeRow設置Spread的操作模式為行定位(共有6種模式)
29.DataSource = Rs設置Spread的數據源為Rs記錄集