2017-09-29 100 views
0

所以我有一個屬性列寬度,我用來存儲列索引和列的寬度,所以當我重新加載我的表格我的列寬度持續(刷新功能),該部分正在工作100%。VB屬性沒有被設置時,從另一種形式設置

''' <summary> 
    ''' Stores the widths of the columns on the form. 
    ''' </summary> 
    ''' <returns></returns> 
    Public Property ColumnWidths As Dictionary(Of Integer, Integer) 
     Get 
      Return _columnWidths 
     End Get 
     Set(ByVal value As Dictionary(Of Integer, Integer)) 
      _columnWidths = value 
     End Set 
    End Property 

但是當我更改顯示的列(當我在我的選項窗體上)時,我想清除該屬性。這是問題所在。

Form1.ColumnWidths = Nothing

我一直在使用一個公共變量試過了,這也不行。有趣的是,我已經在整個解決方案中使用了屬性等,並且所有的工作都是100%的,但這只是在研究我的工具,因爲我從我的選項表單中設置它時沒有保留價值。

我甚至有一個Form1上沒有Get Set部件的屬性,當我從選項窗體中設置它時,它工作正常。然而這個屬性並不想被設置。

這兩個表單都在相同的名稱空間內,並且它會將設置的部分觸發到屬性,但_columnWidths值保持不變。它仍然有我添加到集合中的行。

+1

聽起來好像'Form1'是窗體類的名稱,而不是正在顯示的類的實例。將'Form1'的實例傳遞給選項表單,並使用它來代替'Form1'來訪問表單。 – Blackwood

+0

謝謝@Blackwood,幫助了我。我通過在屬性中添加共享設置來實現它。 '公共共享屬性ColumnWidths作爲詞典(整數,整數)' 現在它已經從使用表單改爲使用正在工作的類:)。謝謝 – Grant

回答

0

將屬性更改爲共享允許選項表單訪問窗體上的Form1類。

''' <summary> 
''' Stores the widths of the columns on the form. 
''' </summary> 
''' <returns></returns> 
Public Shared Property ColumnWidths As Dictionary(Of Integer, Integer) 
    Get 
     Return _columnWidths 
    End Get 
    Set(ByVal value As Dictionary(Of Integer, Integer)) 
     _columnWidths = value 
    End Set 
End Property 
相關問題