Donate

Add An Item To WPF Datagrid (VB.NET)

Hello!

C# Version: Adding An Item to WPF Datagrid (C#)

There was a question on visual basic forum on how to add an item to a wpf datagrid. Here's a simple example below.
Code view:
Dim linkColumn As New DataGridTextColumn : Dim titleColumn As New DataGridTextColumn  
linkColumn.Header = "Links:" : titleColumn.Header = "Titles:"  
linkColumn.Width = dataGrid.Width / 2 : titleColumn.Width = dataGrid.Width / 2  
linkColumn.Binding = New System.Windows.Data.Binding("Link") : titleColumn.Binding =   
New System.Windows.Data.Binding("Title")  
dataGrid.Columns.Add(linkColumn) : dataGrid.Columns.Add(titleColumn)  
dataGrid.Items.Add(New DataItems() With {.Link = "http://testingme.com", .Title = "mytesting"})
XAML:
 <DataGrid AutoGenerateColumns="False" Height="289" HorizontalAlignment="Left" Margin="10,10,0,0" Name="dataGrid"   
          VerticalAlignment="Top" Width="481" Grid.ColumnSpan="2" ItemsSource="{Binding }">  
     </DataGrid>  
VB.NET Class
     Private _link As String  
         Public Property Link() As String  
           Get  
             Return _link  
           End Get  
          Set(ByVal l As String)  
             _link = l  
           End Set  
         End Property  
        Private _title As String  
        Public Property Title() As String  
          Get  
            Return _title  
          End Get  
          Set(ByVal t As String)  
            _title = t  
          End Set  
        End Property

That's it... :)

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input