Search code examples
wpfgridsyncfusion

vb.net syncfusion grid in WPF


I'm trying to create a very simple WPF application to test Syncfusion Grid in VB.NET

I created a simple window and inserted in the designer a ScrollViewer and a Syncfusion GridControl inside it.

this is the window xaml

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ExpenseIt"
        xmlns:syncfusion="http://schemas.syncfusion.com/wpf" x:Class="Window2"
        mc:Ignorable="d"
        Title="Window2" Height="300" Width="537.398">
    <Grid>
        <ScrollViewer HorizontalAlignment="Left" Height="194" Margin="10,10,0,0" VerticalAlignment="Top" Width="380">
            <syncfusion:GridControl Height="100" Width="100"/>
        </ScrollViewer>

    </Grid>
</Window>

Now I tried to create an instance of the grid in the corresponding xaml.vb file

Public Class Window2
    Dim gridControl As Syncfusion.Windows.Controls.Grid

    Private Sub Window2_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded

    End Sub
End Class

But the "Dim" line shows an error says it expect type. What I'm doing wrong?


Solution

  • You are creating an instance of the GridControl in your XAML. Give it an x:Name:

    <syncfusion:GridControl x:Name="grid" Height="100" Width="100"/>
    

    ...and you can access this instance in your code-behind using this name:

    Private Sub Window2_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
        Dum theGrid = grid
        '...
    End Sub
    

    If you try to create another instance, you should use the correct typename:

    Dim gridControl As Syncfusion.Windows.Controls.Grid.GridControl