开发者

Datagrid - no row is displayed

I have a main window with a datagrid in the upper half and a tabcontrol in the lower half. The datagrid contains a list of companies. One of the tabs of the lower tabcontrol contains the information about contact persons corresponding to the company selected in the upper datagrid.

On the tab I place a usercontrol.

<TabItem Name="pgContactsXCompany">
    <local:ContactsXCompany x:Name="contactsXCompany"/>
</TabItem>

The usercontrol "ContactsXCompany" has a datagrid on it with the list of contact persons corresponding to the selected company.

<dg:DataGrid Name="dgContactsXCompanyList" 
             ItemsSource = "{Binding}"
             AutoGenerateColumns="False"
             IsReadOnly="True">
<dg:DataGrid.Columns>
    <dg:DataGridTextColumn Header="Id" Width="Auto" Binding="{Binding Path=intIDContact}" Visibility="Hidden" />
    <dg:DataGridTextColumn Header="Jméno" Width="Auto" Binding="{Binding Path=txtName}" />
    <dg:DataGridTextColumn Header="Příjmení" Width="Auto" Binding="{Binding Path=txtSurname}" />
    <dg:DataGridTextColumn Header="Pobočka" Width="Auto" Binding="{Binding Path=txtBranchOffice}" />
    <dg:DataGridTextColumn Header="Město" Width="Auto" Binding="{Binding Path=txtTown}" />
</dg:DataGrid.Columns> 
</dg:DataGrid>

Contacts are loaded by a function, which takes as a parameter the ID of the company selected (SAP number of the company).

The problem was how to pass the SAP number of the company selected in the开发者_如何学Go upper datagrid to the usercontrol. I created a delegate:

Public Delegate Sub CompanyContactsUpdate(ByVal sap As String)

then on the main window, in the SelectionChanged Sub of the companies datagrid I placed the following code:

Dim doUpdate As CompanyContactsUpdate
Dim obj As New ContactsXCompany
doUpdate = New CompanyContactsUpdate(AddressOf obj.UpdateContactsXCompanyDatagrid)
doUpdate.Invoke(grid.SelectedItem.txtSap)

The function UpdateContactsXCompanyDatagrid is defined on the usercontrol:

Public Class ContactsXCompany
    Public Sub UpdateContactsXCompanyDatagrid(ByVal Sap As String)
        Dim d As New ContactPersonViewModel
        Me.dgContactsXCompanyList.DataContext = d.GetContacts(Sap)
    End Sub
End Class

When I run the application everything works without errors. The Sap number of the selected company is passed to the function UpdateContactsXCompanyDatagrid correctly. The Me.dgContactsXCompanyList.DataContext seems to be assigned, but the contact persons' datagrid is EMPTY. No row is diplayed.

Where should I search the problem? Thanks a lot for your help!


What is the collection type returned from your call to ContactPersonViewModel.GetContacts() ?

I believe it will need to be an ObservableCollection, or some other collection implementing INotifyCollectionChanged.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜