Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binding a grid
Message
From
07/11/2012 15:12:38
 
 
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Miscellaneous
Thread ID:
01556633
Message ID:
01556650
Views:
34
>>Hi,
>>
>>I'm following through the MM.NET 3.6 jump start doing the WPF Application C#, however I am using my own table and forms, not the ones in the jump start.
>>
>>I am trying to do a screen for editing Customers. I have two tabs: List and Properties and have a text box, a search button and a datagrid on the List tab. The user enters some search criteria, hits the Search button which calls my code:
>>
>>
        private void btnSearch_Click(object sender, RoutedEventArgs e)
>>        {
>>            this.DataContext = this.Customer.GetCustomersLikeCustomerLastName(this.txtLastNameSearch.Text);
>>
>>        }
>>
>>
>>The GetCustomers code works fine and returns what I expect, but the list of customers returned does not show in the grid and I get a weird blank window displayed.
>>
>>This is how the grid is defined:
>>
>>
						<Custom:DataGrid Margin="5" x:Name="grdCustomers" IsSynchronizedWithCurrentItem="True" Grid.Row="2" ItemsSource="{Binding Mode=OneWay}" SelectionMode="Single" GridLinesVisibility="None" HeadersVisibility="Column" Grid.Column="0" AutoGenerateColumns="False" Grid.ColumnSpan="1" Style="{DynamicResource HDSDataGridStyle}">
>>                            <Custom:DataGrid.Columns>
>>                                <Custom:DataGridTextColumn Header="Last Name" Width="0.5*" Binding="{Binding cus_LastName, Mode=Default}"/>
>>                                <Custom:DataGridTextColumn Header="First Name" Width="0.5*" Binding="{Binding cus_FirstName, Mode=Default}"/>
>>                            </Custom:DataGrid.Columns>
>>                        </Custom:DataGrid>
>>
>>How does this definition bind the grid to the results of my GetCustomers... code?
>
>Only had time for a quick glance at this. ItemsSource would be the DataContext (assuming nothing in the hierarchy changes this)- i.e the result of GetCustomersLikeCustomerLastName().
>
>>Why does this weird window show?
>
>What does GetCustomersLikeCustomerLastName() return (ObservableCollection might be best) ?

this is the relevant code:
        /// <summary>
        /// Gets customers that match the partial customerLastName string
        /// </summary>
        /// <param name="customerLastName">Partial or full customerLastName string</param>
        /// <returns>List of Customer entities that match the search criteria</returns>
        public mmBindingList<CustomerEntity> GetCustomersLikeCustomerLastName(string customerLastName)
        {
            IQueryable<CustomerEntity> query = from customer in this.ObjectContext.CustomerEntitySet
                                               where customer.cus_lastname.StartsWith(customerLastName)
                                               select customer;

            return this.GetEntityList(query);
        }
still too new to this stuff to be sure how to answer your question. :(
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform