How can I access to TextBoxes in all ListView rows? I have also tried the two-way method, but it is only one-way.
<ListView Name="ListViewParameters" >
<ListView.View>
<GridView>
<GridViewColumn Header="Value" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox x:Name="TextWidth" Text="{Binding Path=Width, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
...
.
Private Sub MainWindow_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
ListViewParameters.ItemsSource = Parameters
End Sub
.
Public Structure Parameter
Private _width As Integer
Private _length As Integer
Private _height As Integer
Property Width() As Integer
Get
Return _width
End Get
Set(Value As Integer)
_width = Value
End Set
End Property
Property Length() As Integer
Get
Return _length
End Get
Set(Value As Integer)
_length = Value
End Set
End Property
Property Height() As Integer
Get
Return _height
End Get
Set(Value As Integer)
_height = Value
End Set
End Property
End Structure
Public ReadOnly Parameters As New ObservableCollection(Of Parameter)
My goal is to calculate the volume:
Private Sub ButtonCalculate_Click(sender As Object, e As RoutedEventArgs)
Dim volume As Integer = 1
For Each t As TextBox In ListParameters
volume *= CInt(t.Text)
Next
MsgBox(volume.ToString)
End Sub
(This is for learning only)
Related
How can I get a Value from a specific Cell in a Datagrid with the Selection Mode FullRow ?
At the moment I use this command, but it only display's the Value if I manually select the cell:
Public Sub MenuItem_Click(sender As Object, e As RoutedEventArgs)
Dim selectedData As String = ""
Dim wert As String = ""
For Each dataGridCellInfo In myGridView.SelectedCells()
Dim pi As Reflection.PropertyInfo = dataGridCellInfo.Item.[GetType]().GetProperty(dataGridCellInfo.Column.Header.ToString())
Dim value = pi.GetValue(dataGridCellInfo.Item, Nothing)
selectedData += dataGridCellInfo.Column.Header + ": " + value.ToString() + vbLf
wert = value.ToString
Next
MessageBox.Show(selectedData)
End Sub
But I don't want to manually select the cell all time.
I just want to click on any cell in that Row and get always the value from the cell "Pfad" and put it in a String.
XAML DataGrid Code:
<DataGrid Name="myGridView" SelectionUnit="Cell" IsReadOnly="True" ItemsSource="{Binding}" Grid.ColumnSpan="3" Background="#FFA4A4A4" BorderThickness="2" BorderBrush="#FF6A6F77" AutoGenerateColumns="False" Margin="10,31,10,149.714" GridLinesVisibility="None">
<DataGrid.Columns>
<DataGridTextColumn Header="Track" Binding="{Binding Path=Track}" Width="100"/>
<DataGridTemplateColumn Header="">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Width="50" Height="50" VerticalAlignment="Center" HorizontalAlignment="Center" Source="{Binding Path=Image}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Path=Endung}" Width="100" Header=" Container"/>
<DataGridTextColumn Binding="{Binding Path=Album}" Width="100" Header="Album"/>
<DataGridTextColumn Binding="{Binding Path=Bitrate}" Width="100" Header="Bitrate"/>
<DataGridTextColumn Binding="{Binding Path=Pfad}" Width="100" Header="Pfad"/>
</DataGrid.Columns>
</DataGrid>
Code-Behind:
Public Structure Austauscher
Dim files As New ObservableCollection(Of Austauscher)
Private _track As String
Private _image As BitmapImage
Private _album As String
Private _pfad As String
Private _bitrate As String
Private _endung As String
Property Track() As String
Get
Return _track
End Get
Set(ByVal Value As String)
_track = Value
End Set
End Property
Property Image As BitmapImage
Get
Return _image
End Get
Set(ByVal Value As BitmapImage)
_image = Value
End Set
End Property
Property Album() As String
Get
Return _album
End Get
Set(ByVal Value As String)
_album = Value
End Set
End Property
Public Property Pfad As String
Get
Return _pfad
End Get
Set(ByVal Value As String)
_pfad = Value
End Set
End Property
Property Bitrate As String
Get
Return _bitrate
End Get
Set(ByVal Value As String)
_bitrate = Value
End Set
End Property
Property Endung As String
Get
Return _endung
End Get
Set(ByVal Value As String)
_endung = Value
End Set
End Property
End Structure
At first you need tu open de event "CellClick" on your datagridview and put de following code:
If (e.ColumnIndex <> -1) And (e.RowIndex <> -1) Then
Dim selectedCell as string = ""
selectedCell = myGridView.rows(e.rowIndex).cells("numberOfCell").valeu
End If
If this Answer has help you. Pleas mark this at the correct Answer.
I am creating my own NumericUpDown control in VB. Here is my XAML:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
x:Class="NumericUpDown"
mc:Ignorable="d"
d:DesignHeight="30" d:DesignWidth="100">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<TextBox x:Name="txtNum" Grid.Column="0" x:FieldModifier="private" TextChanged="txtNum_TextChanged"/>
<Button x:Name="cmdDown" Grid.Column="1" x:FieldModifier="private" Content="˅" Width="20" Click="cmdDown_Click" />
<Button x:Name="cmdUp" Grid.Column="2" x:FieldModifier="private" Content="˄" Width="20" Click="cmdUp_Click" />
</Grid>
</UserControl>
And here is the VB code behind it:
Class NumericUpDown
Dim _Minimum As Double = 0
Dim _Maximum As Double = 100
Private Sub NumericUpDown()
InitializeComponent()
txtNum.Text = Numeric
End Sub
Public Property Maximum As Double
Get
Return _Maximum
End Get
Set(value As Double)
_Maximum = value
End Set
End Property
Public Property Minimum As Double
Get
Return _Minimum
End Get
Set(value As Double)
_Minimum = value
End Set
End Property
Public Shared ReadOnly NumericProperty As DependencyProperty = DependencyProperty.Register("Numeric", GetType(String), GetType(NumericUpDown), _
New PropertyMetadata(""))
Public Property Numeric As String
Get
Return CType(GetValue(NumericProperty), String)
End Get
Set(value As String)
SetValue(NumericProperty, value)
End Set
End Property
Private Sub cmdUp_Click(sender As Object, e As RoutedEventArgs)
Dim NumValue As Double
NumValue = Val(txtNum.Text)
NumValue += 1
If NumValue > Maximum Then NumValue = Maximum
txtNum.Text = NumValue.ToString
End Sub
Private Sub cmdDown_Click(sender As Object, e As RoutedEventArgs)
Dim NumValue As Double
NumValue = Val(txtNum.Text)
NumValue -= 1
If NumValue < Minimum Then NumValue = Minimum
txtNum.Text = NumValue.ToString
End Sub
Private Sub txtNum_TextChanged(sender As Object, e As TextChangedEventArgs)
Numeric = txtNum.Text
End Sub
End Class
I use it in my page like this:
Put this on page definition:
xmlns:local="clr-namespace:Demo"
And put this in the content section:
<local:NumericUpDown Numeric="{Binding Path=score, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}"/>
Of course I have already set DataContext on the container and all other databound controls work as they should. But the textbox in my custom control turned out empty! It doesn't end here. When I type something in the textbox and when I give it some value using decrease and increase button, the value is transferred to my DataTable; which means this usercontrol does work to some extend. Where did I do wrong? Why won't the Textbox content be initialized with the starting value?
After a little more testing. It seems that my usercontrol doesn't work in 'Two-Way'. It doesn't receive data from DataTable, it only propagates value to it. How do I fix it?
The issue is that you are not binding the Text property of txtNum to your Numeric property.
<TextBox x:Name="txtNum" Grid.Column="0" x:FieldModifier="private"
Text="{Binding Path=Numeric, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/>
Then you can remove txtNum_TextChanged, and modify your up/down click handlers to just update the Numeric property, e.g.:
Private Sub cmdUp_Click(sender As Object, e As RoutedEventArgs)
If Me.Numeric < Me.Maximum Then
Me.Numeric += 1
Else
Me.Numeric = Me.Maximum
End If
End Sub
Private Sub cmdDown_Click(sender As Object, e As RoutedEventArgs)
If Me.Numeric > Me.Minimum Then
Me.Numeric -= 1
Else
Me.Numeric = Me.Minimum
End If
End Sub
Note that there are still lots of issues - a user can enter a value outside of the allowed range, or non-numeric data (which will break things!), etc. For this specific problem, you could check out the Extended EPF Toolkit, which has various up/down controls.
I have a UI element which is a listview that contains in it another listview (one vertical and one horizontal).
The Itemsource of the the First listview is an ObservableCollection of Objects, which in turn contains ObservableCollection of a child object. Both have INotifyPropertyChanged interface implemented and call the PropetyChanged Event when usefull.
If I added new child object, I see my second listview update, but when I change a value, I do not see anything change. Is there anything I must do to refresh my UI element in this case ?
Here is my listview
<ListView x:Name="LstInfoEtape" Margin="0,0,0,0" Style="{StaticResource BaseListView}" Grid.Row="2" Grid.Column="1" >
<ListView.ItemTemplate>
<DataTemplate>
<ListView x:Name="LstEtape" ItemsSource="{Binding LstEtapes}" Background="#00000000" SelectionChanged="ListView_SelectionChanged" ScrollViewer.ScrollChanged="ListView_ScrollChanged">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<Border Width="82" CornerRadius="4" BorderBrush="{Binding ColorSelected}" BorderThickness="3,3,3,3" Visibility="{Binding EtapeVisible}" Background="{Binding ColorBackground}" MouseDown="Border_MouseDown">
<Grid Width="80" >
<Grid.RowDefinitions>
<RowDefinition Height="19"/>
</Grid.RowDefinitions>
<TextBlock Margin="2,0,2,0" x:Name="TxtDateRappel" TextWrapping="Wrap" Grid.Row="0" Text="{Binding DateRappelTerminaison,StringFormat=yyyy-MM-dd,NotifyOnSourceUpdated=True}" Visibility="{Binding EtapeVisible}" FontSize="12" Foreground="{Binding ColorForeground}" />
</Grid>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
The classes I use are those
Public Class SuiviOperationLite
Implements INotifyPropertyChanged
Private _strNom As String
Private _oLstProcessusLite As ObservableCollection(Of ContratProcessusLite) ' Not implemented yet
Private _oLstEtapeLite As ObservableCollection(Of ContratProcessusEtapeLite)
Public Sub New(ByVal strNom As String,
ByVal oLstProcessusLite As ObservableCollection(Of ContratProcessusLite),
ByVal oLstEtapeLite As ObservableCollection(Of ContratProcessusEtapeLite))
Constructor(strNom, oLstProcessusLite, oLstEtapeLite)
End Sub
Private Sub Constructor(ByVal strNom As String,
ByVal oLstProcessusLite As ObservableCollection(Of ContratProcessusLite),
ByVal oLstEtapeLite As ObservableCollection(Of ContratProcessusEtapeLite))
_strNom = strNom
_oLstProcessusLite = oLstProcessusLite
_oLstEtapeLite = oLstEtapeLite
End Sub
Public Property Nom() As String
Get
Return _strNom
End Get
Set(ByVal value As String)
_strNom = value
End Set
End Property
Public Property LstContratProcessus() As ObservableCollection(Of ContratProcessusLite)
Get
Return _oLstProcessusLite
End Get
Set(ByVal value As ObservableCollection(Of ContratProcessusLite))
_oLstProcessusLite = value
End Set
End Property
Public Property LstEtapes() As ObservableCollection(Of ContratProcessusEtapeLite)
Get
Return _oLstEtapeLite
End Get
Set(ByVal value As ObservableCollection(Of ContratProcessusEtapeLite))
_oLstEtapeLite = value
End Set
End Property
Protected Friend Sub NotifyPropertyChanged(ByVal info As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
End Sub
Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
End Class
Public Class ContratProcessusEtapeLite
Implements INotifyPropertyChanged
Private _lngId As Long
Private _lngIdSequenceTravail As Long
Private _boolSelected As Boolean
Private _strETapeVisible As String
Private _strColorBackGround As String
Private _strColorForeGround As String
Private _dateRappelTerminaison As Date
Private _oParent As DAL.SuiviOperationLite
Public Sub New(ByVal oParent As DAL.SuiviOperationLite,
ByVal lngId As Long,
ByVal lngIdSequenceTravail As Long,
ByVal boolSelected As Boolean,
ByVal strEtapeVisible As String,
ByVal strColorBackGround As String,
ByVal strColorForeGround As String,
ByVal dateRappelTerminaison As Date)
Constructor(oParent,
lngId, _
lngIdSequenceTravail, _
boolSelected, _
strEtapeVisible, _
strColorBackGround, _
strColorForeGround, _
dateRappelTerminaison)
End Sub
Private Sub Constructor(ByVal oParent As DAL.SuiviOperationLite,
ByVal lngId As Long,
ByVal lngIdSequenceTravail As Long,
ByVal boolSelected As Boolean,
ByVal strEtapeVisible As String,
ByVal strColorBackGround As String,
ByVal strColorForeGround As String,
ByVal dateRappelTerminaison As Date)
_oParent = oParent
_lngId = lngId
_lngIdSequenceTravail = lngIdSequenceTravail
_boolSelected = boolSelected
_strETapeVisible = strEtapeVisible
_strColorBackGround = strColorBackGround
_strColorForeGround = strColorForeGround
_dateRappelTerminaison = dateRappelTerminaison
End Sub
Public Property Parent() As DAL.SuiviOperationLite
Get
Return _oParent
End Get
Set(ByVal value As DAL.SuiviOperationLite)
_oParent = value
End Set
End Property
Public Property ID() As Long
Get
Return _lngId
End Get
Set(ByVal value As Long)
_lngId = value
NotifyPropertyChanged("ID")
End Set
End Property
Public Property IdClientContratSequenceTravail() As Long
Get
Return _lngIdSequenceTravail
End Get
Set(ByVal value As Long)
_lngIdSequenceTravail = value
NotifyPropertyChanged("IdSequence")
End Set
End Property
Public Property Selected() As Boolean
Get
Return _boolSelected
End Get
Set(ByVal value As Boolean)
_boolSelected = value
NotifyPropertyChanged("Selected")
End Set
End Property
Public ReadOnly Property ColorSelected As String
Get
If _boolSelected Then
Return "#FF4394DF"
Else
Return "#FF000000"
End If
End Get
End Property
Public Property EtapeVisible() As String
Get
Return _strETapeVisible
End Get
Set(ByVal value As String)
_strETapeVisible = value
NotifyPropertyChanged("Visible")
End Set
End Property
Public Property ColorBackground() As String
Get
Return _strColorBackGround
End Get
Set(ByVal value As String)
_strColorBackGround = value
NotifyPropertyChanged("Background")
End Set
End Property
Public Property ColorForeground() As String
Get
Return _strColorForeGround
End Get
Set(ByVal value As String)
_strColorForeGround = value
NotifyPropertyChanged("Foreground")
End Set
End Property
Public Property DateRappelTerminaison() As Date
Get
Return _dateRappelTerminaison
End Get
Set(ByVal value As Date)
_dateRappelTerminaison = value
NotifyPropertyChanged("DateRappel")
End Set
End Property
Private Sub NotifyPropertyChanged(ByVal info As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
_oParent.NotifyPropertyChanged("Child")
End Sub
Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
End Class
And here are the functions (There are more processing to get the collection of items, but I doubt it's really relevant :
Private Sub LoadList(colSuivi as ObservableCollection(Of SuiviProductionLite)
LstInfoEtape.ItemsSource = colSuivi
End Sub
Private Sub Border_MouseDown(sender As System.Object, e As System.Windows.Input.MouseButtonEventArgs)
Dim oBorder As Border
Dim oEtapeLite As DAL.ContratProcessusEtapeLite
Select Case e.Source.GetType.ToString
Case "System.Windows.Controls.TextBlock"
Dim oTxt As TextBlock = e.Source
Dim oGrid As Grid = oTxt.Parent
_oCurBorderDet = oGrid.Parent
Case "System.Windows.Controls.Border"
Dim oBrd As Border = e.Source
_oCurBorderDet = e.Source
End Select
If Not _oCurBorderDet.DataContext.GetType().FullName.Equals("MS.Internal.NamedObject") Then
oEtapeLite = _oCurBorderDet.DataContext
oEtapeLite.Selected = True
End If
End Sub
When I do some tracing, I know that both PropertyChanged Events are call wheter I click on my UI. If I do a manual "Items.Refresh", I can also see the UI being changed, but I want to remove that manual refresh as it refresh everything, not only the item just modified, which, when facing a lot of data, takes much more time.
I see one problem
Public Property IdClientContratSequenceTravail() As Long
Get
Return _lngIdSequenceTravail
End Get
Set(ByVal value As Long)
_lngIdSequenceTravail = value
NotifyPropertyChanged("IdSequence")
End Set
End Property
Wrong name in Notify
I've been hunting through stackoverflow for a while to answer this.
I've got a Listview who's items are Listviews whose children are actually a list(of string) that is a member of the parent listviewitem.
Drag and drop functionality is the goal. However this is proving hard for a variety of reasons, one of which is casting. I need to get the type before I do a direct cast to make it work - at least I think that will get me over one problem.
However I can't get this syntax to even begin to work, so I'll start here:
Dim itemType = listView.ItemContainerGenerator.ItemFromContainer(listViewItem)
Dim g As Type = GetType(itemtype)
This is the entire drag n drop implementation I'm trying:
Dim startpoint As Point
Public Sub List_PreviewMouseLeftButtonDown(sender As Object, e As MouseEventArgs)
' Store the mouse position
startpoint = e.GetPosition(Nothing)
End Sub
Private Sub List_MouseMove(sender As Object, e As MouseEventArgs)
Dim mousePos As Point = e.GetPosition(Nothing)
Dim diff As Vector = startpoint - mousePos
If e.LeftButton = MouseButtonState.Pressed And Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance Or Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance Then
Dim listView As ListView = DirectCast(sender, ListView)
Dim listViewItem As ListViewItem = FindAncestor(Of ListViewItem)(DirectCast(e.OriginalSource, DependencyObject))
Dim itemType = listView.ItemContainerGenerator.ItemFromContainer(listViewItem)
Dim g As Type = GetType(itemtype)
Dim item As String = DirectCast(listView.ItemContainerGenerator.ItemFromContainer(listViewItem), String)
Dim dragData As New DataObject("myFormat", item)
DragDrop.DoDragDrop(listViewItem, dragData, DragDropEffects.Move)
End If
End Sub
Private Shared Function FindAncestor(Of T As DependencyObject)(current As DependencyObject) As T
Do
If TypeOf current Is T Then
Return DirectCast(current, T)
End If
current = VisualTreeHelper.GetParent(current)
Loop While current IsNot Nothing
Return Nothing
End Function
Private Sub DropList_DragEnter(sender As Object, e As DragEventArgs)
If Not e.Data.GetDataPresent("myFormat") OrElse sender = e.Source Then
e.Effects = DragDropEffects.None
End If
End Sub
Private Sub DropList_Drop(sender As Object, e As DragEventArgs)
If e.Data.GetDataPresent("myFormat") Then
Dim contact As String = TryCast(e.Data.GetData("myFormat"), String)
Dim listView As ListView = TryCast(sender, ListView)
listView.Items.Add(contact)
End If
End Sub
Here is the nested listView:
<!--DataContext="{StaticResource RcpdInsertViewSource}" This is a collectionviewsource.
RCPDInsert has a list(of string) member that is created from a single string property
and whose order needs to be alterable.
Eg rcpdInsert.template="[stuff] [more stuff]" so rcpdInsert.templateList = list(of String) from template.split("] [") -->
<ListView Grid.Column="1" Grid.Row="1" ItemsSource="{Binding}"
PreviewMouseLeftButtonDown="List_PreviewMouseLeftButtonDown"
PreviewMouseMove="List_MouseMove"
Drop="DropList_Drop"
DragEnter="DropList_DragEnter"
AllowDrop="True">
<ListView.ItemTemplate>
<DataTemplate>
<DockPanel>
<TextBox Text="{Binding Path=cpID}"></TextBox>
<TextBox Text="{Binding Path=fieldRef}"></TextBox>
<ListView ItemsSource="{Binding Path=InsertsList}" >
<ListView.ItemTemplate>
<DataTemplate DataType="DataClasses1:RcpdInsert.template" >
<StackPanel Orientation="Horizontal" Grid.Row="0">
<TextBlock Text="{Binding}" Margin="5" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DockPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Goal: Drag and drop reordering of child listviews, ideally being able to pull individual items from one child listView to another. When saved, the code behind will actually concat the strings back together and update the template member.
For context here are the relevant members of RcpdInsert:
Sub SetupInsertList()
_insertsList = template.Split(" ").ToList()
For Each item In InsertsList
Dim t = item
RcpdList.Add(RcpdSet.RpcdListShared.Where(Function(x) x.insertID = t).ToList())
Next
End Sub
Public Property RcpdList As New List(Of List(Of Rcpd))
Private Property _insertsList As New List(Of String)
Public Property InsertsList As List(Of String)
Get
If _insertsList.Count = 0 Then setupInsertList()
Return _insertsList
End Get
Set(value As List(Of String))
Dim combine As String = value.Aggregate("", Function(current, i) current + (i & " "))
template = combine
End Set
End Property
The casting is one issue with this, I'm hoping being able to do this part means that the others will be easier to resolve.
Thanks in advance to anyone who can help :)
I have a couple tables dealing with cars:
<Table(Name:="tblManufacturer")> Public Class dbManufacturers
Private _ManufacturerID As Integer
<Column(Storage:="_ManufacturerID", DbType:="int IDENTITY NOT NULL", IsPrimaryKey:=True, IsDbGenerated:=True, Name:="ManufacturerID")> _
Public Property ManufacturerID() As Integer
Get
Return Me._ManufacturerID
End Get
Set(value As Integer)
Me._ManufacturerID = value
End Set
End Property
Private _ManufacturerName As String
<Column(Storage:="_ManufacturerName", DbType:="Varchar(50)", Name:="ManufacturerName")> _
Public Property ManufacturerName() As String
Get
Return Me._ManufacturerName
End Get
Set(value As String)
Me._ManufacturerName = value
End Set
End Property
Private _Models As EntitySet(Of dbModels) = New EntitySet(Of dbModels)
<Association(Storage:="_Models", DeleteRule:="CASCADE", OtherKey:="ManufacturerID")> _
Public Property Models As EntitySet(Of dbModels)
Get
Return _Models
End Get
Set(value As EntitySet(Of dbModels))
_Models.Assign(value)
End Set
End Property
End Class
<Table(Name:="tblModels")> Public Class dbModels
Private _ModelID As Integer
<Column(Storage:="_ModelID", DbType:="int IDENTITY NOT NULL", IsPrimaryKey:=True, IsDbGenerated:=True, Name:="ModelID")> _
Public Property ModelID() As Integer
Get
Return Me._ModelID
End Get
Set(value As Integer)
Me._ModelID = value
End Set
End Property
Private _ManufacturerID As Integer
<Column(Storage:="_ManufacturerID", DbType:="int", Name:="ManufacturerID")> _
Public Property ManufacturerID() As Integer
Get
Return Me._ManufacturerID
End Get
Set(value As Integer)
Me._ManufacturerID = value
End Set
End Property
Private _ModelName As String
<Column(Storage:="_ModelName", DbType:="Varchar(200)", Name:="ModelName")> _
Public Property ModelName() As String
Get
Return Me._ModelName
End Get
Set(value As String)
Me._ModelName = value
End Set
End Property
End Class
The XAML:
<TreeView Name="TreeView1" Margin="3" ItemsSource="{Binding ElementName=ManufacturerInfo, Path=tblManufacturers}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate>
<TextBlock Text="{Binding Path=ManufacturerName}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Source=Models, Path=ModelName}" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
The code behind:
Public Class ManufacturerInfo
Private LinqDB As New DataContext(My.Settings.dbConnection)
Property tblManufacturers As Table(Of dbManufacturers) = LinqDB.GetTable(Of dbManufacturers)()
Public Sub New()
InitializeComponent()
End Sub
Private Sub ManufacturerInfo_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
Me.DataContext = Me
End Sub
End Class
So I get the list of Manufacturers, but not the nested models. Is there a way to make this work, or do I have to change how I'm doing my LINQ query?
I'm having trouble finding similar treeview examples.
Figured it out.
Still have a bit to learn about the subtle art of data binding.
<TreeView Name="TreeView1" Margin="3" ItemsSource="{Binding ElementName=ManufacturerInfo, Path=tblManufacturers}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=Models}">
<TextBlock Text="{Binding Path=ManufacturerName}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=ModelName}" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>