Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found the other answer confusing because of the inline-comments... adding a columnDEFINITION (for example) "draws" absolutely NOTHING - that's very misleading for beginners. </p> <p>Also : the rows are selected repeatedly even though they have already been selected ... that just adds useless overhead. This will make your app really really slow if you're using several hundred rows. </p> <p>Same with setting the WindowHeight.</p> <p>Here's a (somewhat) more efficient solution for dynamic row&amp;column-management in VB.NET: (use Dispatcher.BeginInvoke() instead of Invoke() if you want to switch to asynchronous processing)</p> <pre><code>Private Delegate Sub MyDelegate3(ByVal iByte As Byte) Private Delegate Function MyDelegate4() As Byte Public Property GridColumns As Byte Get Dim del As New MyDelegate4(AddressOf GetColumns) Return grid.Dispatcher.Invoke(del) End Get Set(ByVal value As Byte) Dim del As MyDelegate3 If GridColumns &gt; 0 Then Dim diff As SByte = GridColumns - value If diff &gt; 0 Then 'Spalten abziehen del = New MyDelegate3(AddressOf RemColDefs) grid.Dispatcher.Invoke(del, diff) Else 'Spalten hinzufügen del = New MyDelegate3(AddressOf AddColDefs) grid.Dispatcher.Invoke(del, Math.Abs(diff)) End If Else del = New MyDelegate3(AddressOf AddColDefs) grid.Dispatcher.Invoke(del, value) End If End Set End Property Public Property GridRows As Byte Get Dim del As New MyDelegate4(AddressOf GetRows) Return grid.Dispatcher.Invoke(del) End Get Set(value As Byte) Dim del As MyDelegate3 If GridRows &gt; 0 Then Dim diff As SByte = GridRows - value If diff &gt; 0 Then 'Zeilen abziehen del = New MyDelegate3(AddressOf RemRowDefs) grid.Dispatcher.Invoke(del, diff) Else 'Spalten hinzufügen del = New MyDelegate3(AddressOf AddRowDefs) grid.Dispatcher.Invoke(del, Math.Abs(diff)) End If Else del = New MyDelegate3(AddressOf AddRowDefs) grid.Dispatcher.Invoke(del, value) End If End Set End Property Private Function GetRows() As Byte Return grid.RowDefinitions.Count End Function Private Function GetColumns() As Byte Return grid.ColumnDefinitions.Count End Function Private Sub AddRowDefs(ByVal iRows As Byte) For r As Byte = 1 To iRows Dim rowDef As New RowDefinition rowDef.Height = GridLength.Auto grid.RowDefinitions.Add(rowDef) Next End Sub Private Sub RemRowDefs(ByVal iRows As Byte) For r As Byte = 1 To iRows If grid.RowDefinitions.Count &gt; 0 Then grid.RowDefinitions.Remove(grid.RowDefinitions(0)) End If Next End Sub Private Sub AddColDefs(ByVal iCols As Byte) For r As Byte = 1 To iCols Dim colDef As New ColumnDefinition colDef.Width = GridLength.Auto grid.ColumnDefinitions.Add(colDef) Next End Sub Private Sub RemColDefs(ByVal iCols As Byte) For r As Byte = 1 To iCols If grid.ColumnDefinitions.Count &gt; 0 Then grid.ColumnDefinitions.Remove(grid.ColumnDefinitions(0)) End If Next End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload