Last active
March 24, 2019 05:08
-
-
Save axzxc1236/680d6bf58fb0b65dd718e106452371a8 to your computer and use it in GitHub Desktop.
[VB.NET] Access WPF Datagrid with texts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I don't know why I can't find this on Google. (I tried and found *nothing* helpful) | |
Given the DataGrid below | |
<DataGrid x:Name="DataGrid1" HorizontalAlignment="Left" Height="229" Margin="70,96,0,0" VerticalAlignment="Top" Width="497"> | |
<DataGrid.Columns> | |
<DataGridTextColumn Binding="{Binding A}" ClipboardContentBinding="{x:Null}" Header="A"/> | |
<DataGridTextColumn Binding="{Binding B}" ClipboardContentBinding="{x:Null}" Header="B"/> | |
<DataGridTextColumn Binding="{Binding C}" ClipboardContentBinding="{x:Null}" Header="C"/> | |
</DataGrid.Columns> | |
</DataGrid> | |
We can add items to DataGrid1 with following code | |
DataGrid1.Items.Add(New With { | |
.A = "A", | |
.B = "B", | |
.C = "C" | |
}) | |
For the sake of tutorial we add more items to DataGrid1 | |
DataGrid1.Items.Add(New With { | |
.A = "A2", | |
.B = "B2", | |
.C = "C2" | |
}) | |
DataGrid1.Items.Add(New With { | |
.A = "A3", | |
.B = "B3", | |
.C = "C3" | |
}) | |
Now to access "A" we can use the following code | |
DataGrid1.Items(0).A | |
For example: MsgBox(DataGrid1.Items(0).A) | |
To access "A2" we use : | |
DataGrid1.Items(1).A | |
To access "C3" we use : | |
DataGrid1.Items(2).C | |
...So far and so on. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment