原創(chuàng)|其它|編輯:郝浩|2012-11-27 09:39:51.000|閱讀 332 次
概述:在Spread Windows Forms中手動創(chuàng)建分級顯示的使用教程,附加源。在本文中將會創(chuàng)建兩個自定義的SheetView對象,一個作為父級,一個作為子級
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在本文中將會創(chuàng)建兩個自定義的SheetView對象,一個作為父級,一個作為子級。在父級中重寫了ChildRelationCount 和 GetChildView 和 FindChildView 方法,ChildRelationCount顯示著對象和子對象之間多少的關(guān)系,GetChildView則是備用來看看是否創(chuàng)建了工作表格,如果是應(yīng)經(jīng)創(chuàng)建了,那么就使用這一個,如果沒有,就重新再創(chuàng)建一個新的子表格,子SheetView決定著表格名字屬性分配給哪一個父級行,然后在子SheetView中覆蓋arentRowIndex的屬性來返回子表格所屬于的行號,而創(chuàng)建這個表的SheetName決定了這個數(shù)字。
所用到的代碼如下:
VB:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load FpSpread1.Sheets.Clear() FpSpread1.Sheets.Add(New customSheet) FpSpread1.Sheets(0).RowCount = 10 Dim i As Integer For i = 0 To 9 If i <> 1 Then FpSpread1.Sheets(0).SetRowExpandable(i, False) End If Next i End Sub End Class Public Class customSheet Inherits FarPoint.Win.Spread.SheetView Public Overrides ReadOnly Property ChildRelationCount() As Integer Get Return 1 End Get End Property Public Overrides Function GetChildView(ByVal row As Integer, ByVal relationIndex As Integer) As FarPoint.Win.Spread.SheetView Dim child As customChild = CType(FindChildView(row, 0), customChild) If Not (child Is Nothing) Then Return child child = New customChild child.RowCount = 5 child.Parent = Me child.SheetName = row.ToString ChildViews.Add(child) Return child End Function Public Overrides Function FindChildView(ByVal row As Integer, ByVal relationIndex As Integer) As FarPoint.Win.Spread.SheetView Dim id As String = row.ToString Dim View As FarPoint.Win.Spread.SheetView For Each View In ChildViews If View.SheetName = id Then Return View Next Return Nothing End Function End Class Public Class customChild Inherits FarPoint.Win.Spread.SheetView Public Overrides ReadOnly Property ParentRowIndex() As Integer Get Return CInt(SheetName) End Get End Property End Class
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件