Click here to Skip to main content
15,887,746 members
Home / Discussions / WPF
   

WPF

 
QuestionSilverlight file is not diplayed Pin
Rajeeeeee13-Jul-09 20:28
Rajeeeeee13-Jul-09 20:28 
AnswerRe: Silverlight file is not diplayed Pin
Mark Salsbery14-Jul-09 8:16
Mark Salsbery14-Jul-09 8:16 
GeneralRe: Silverlight file is not diplayed Pin
nizam babu30-Aug-09 22:49
nizam babu30-Aug-09 22:49 
QuestionMessage Removed Pin
13-Jul-09 10:59
professionalN_tro_P13-Jul-09 10:59 
AnswerRe: WPF animation background processing Pin
Christian Graus13-Jul-09 11:25
protectorChristian Graus13-Jul-09 11:25 
QuestionDataGrid Bindings not working Pin
Jacobus0113-Jul-09 4:06
Jacobus0113-Jul-09 4:06 
AnswerRe: DataGrid Bindings not working Pin
laprathab13-Jul-09 21:50
laprathab13-Jul-09 21:50 
GeneralRe: DataGrid Bindings not working Pin
Jacobus0113-Jul-09 22:36
Jacobus0113-Jul-09 22:36 
OK,

This is the XAML for the Datagrid:

<my:DataGrid CanUserAddRows="True" RowHeaderWidth="10" CanUserResizeRows="False" Margin="235,344,38,93" RowHeaderStyle="{StaticResource RowHeaderStyle}" ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}" HeadersVisibility="All" Name="TenderDataGrid" ItemsSource="{Binding Path=TenderLineItems}" AutoGenerateColumns="False" ColumnWidth="SizeToHeader" IsReadOnly="False" SelectionChanged="TenderDataGrid_SelectionChanged" CanUserSortColumns="False" SelectionMode="Single" SelectionUnit="CellOrRowHeader" IsSynchronizedWithCurrentItem="True" Background="#FFDDDDDD" BorderBrush="#FFAAAAAA" BorderThickness="3" AlternatingRowBackground="LightBlue">
     <my:DataGrid.Columns>
                              <my:DataGridTextColumn Header="Series" Binding="{Binding Path=Series, Mode=TwoWay}" Width="Auto"></my:DataGridTextColumn>
                              <my:DataGridTextColumn Header="Item No" Binding="{Binding Path=ItemNo, Mode=TwoWay}"></my:DataGridTextColumn>
                              <my:DataGridTextColumn Header="Description" Binding="{Binding Path=Description, Mode=TwoWay}" MinWidth="200"></my:DataGridTextColumn>
                              <my:DataGridTextColumn Header="Unit" Binding="{Binding Path=Unit, Mode=TwoWay}"></my:DataGridTextColumn>
                              <my:DataGridTextColumn Header="Quantity" Binding="{Binding Path=Qty, Mode=TwoWay}"></my:DataGridTextColumn>
                              <!--<my:DataGridTextColumn Width="5000"></my:DataGridTextColumn>-->
                        </my:DataGrid.Columns>     
                  </my:DataGrid>

(Sorry about the indentation)

I have a class that defines an observable collection:

using System.Collections.ObjectModel;
using MMSDLL;

namespace Tender_Module
{
      class TenderItemModel
      {
            public ObservableCollection<ITenderLineItem> TenderLineItems {get;set;}

      }
}

This is the interface that I use to be able to add Items to the grid:

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;

namespace MMSDLL
{
      public interface ITenderLineItem
      {
            int RateSize { get; set; }
            string Series { get; set; }
            string Description { get; set; }
            string ItemNo { get; set;}
            string Unit { get; set; }
            double? Qty { get; set; }
            double Rate1 { get; set; }
            double Rate2 { get; set; }
            double Rate3 { get; set; }
            double Rate4 { get; set; }
            double Rate5 { get; set; }
            double Rate6 { get; set; }
            double Rate7 { get; set; }
            double Rate8 { get; set; }
            double Rate9 { get; set; }
            double Rate10 { get; set; }
            double Rate11 { get; set; }
            double Rate12 { get; set; }
            double Rate13 { get; set; }
            double Rate14 { get; set; }
            double Rate15 { get; set; }
            double Rate16 { get; set; }
            double Rate17 { get; set; }
            double Rate18 { get; set; }
            double Rate19 { get; set; }
            double Rate20 { get; set; }
            double Rate21 { get; set; }
            double Rate22 { get; set; }
            double Rate23 { get; set; }
            double Rate24 { get; set; }
            double Rate25 { get; set; }
            double Rate26 { get; set; }
            double Rate27 { get; set; }
            double Rate28 { get; set; }
            double Rate29 { get; set; }
            double Rate30 { get; set; }
            double Rate31 { get; set; }
            double Rate32 { get; set; }
            double Rate33 { get; set; }
            double Rate34 { get; set; }
            double Rate35 { get; set; }
            double Rate36 { get; set; }
            double Rate37 { get; set; }
            double Rate38 { get; set; }
            double Rate39 { get; set; }
            double Rate40 { get; set; }
      }
}

Then on my main Window where I define the DataGrid, This is the code I use to set the DataContext:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SYSTEM_LIB_DLL;
using SYSTEM_LIB_DLL.Entity;
using Microsoft.Windows.Controls;
using MMSDLL;

namespace Tender_Module
{
      /// <summary>
      /// Interaction logic for Window1.xaml
      /// </summary>
      public partial class Window1 : Window
      {
            private ObservableCollection<ITenderLineItem> LineItems = new ObservableCollection<ITenderLineItem>();
            private TenderItemModel TM;
            private Tender InstanceTender;
            private const string COMPANY_NAME = "Infrastructure Systems Integrators - Tender Module";
            private int seriesPosition = 0;
            private string operation;
            private RateHandler InstanceRateHandler = null;

            public RateHandler CurrentRateHandler
            {
                  get
                  {
                        return InstanceRateHandler;
                  }
                  set
                  {
                        InstanceRateHandler = value;
                  }
            }

            public Window1()
            {
                  InitializeComponent();
                  this.Title = COMPANY_NAME;
                  TM = new TenderItemModel { TenderLineItems = LineItems };
                  TenderDataGrid.DataContext = TM;
                  MainGrid.Visibility = Visibility.Hidden;
            }
           
This is just the first part of a very large class so I'm leaving out the rest of the class and I'll just show the relevant methods that I use:


Now after i've added a few ITenderLineItems to the grid, i want to add new columns to the grid and set their bindings.


            private void CreateRateColumns(int numColumns)
            {

                  for (int i = 1; i <= numColumns; i++)// Iterate numColumns
                  {
                 
                              DataGridTextColumn RateColumn = new DataGridTextColumn();
                              Binding theBinding = new Binding("Rate" + i);
                              RateColumn.Binding = theBinding;
                              RateColumn.Header = "Rate " + i + " ";
                              RateColumn.IsReadOnly = false;
                              TenderDataGrid.Columns.Add(RateColumn);
                  }
            }

This method is relatively straightforward but what happens is that the bindings don't work on the Datagrid after it has been populated with ITenderLineItems instances. If I create the columns before adding these objects to it, then all is well. Now I'm getting a NullReferenceException on the grid if i enter a text value in one of these Dynamicly created columns' cells. I need this grid to adapt to the settings that the user change as long as the program is running. This is quite a thorn in my flesh
QuestionDisplaying Data fetched asyncronously Pin
Adriaan Davel12-Jul-09 20:27
Adriaan Davel12-Jul-09 20:27 
AnswerRe: Displaying Data fetched asyncronously Pin
Mark Salsbery15-Jul-09 10:13
Mark Salsbery15-Jul-09 10:13 
GeneralRe: Displaying Data fetched asyncronously Pin
Adriaan Davel15-Jul-09 19:46
Adriaan Davel15-Jul-09 19:46 
GeneralRe: Displaying Data fetched asyncronously Pin
Michael Sync23-Jul-09 7:03
Michael Sync23-Jul-09 7:03 
GeneralRe: Displaying Data fetched asyncronously Pin
Adriaan Davel23-Jul-09 19:52
Adriaan Davel23-Jul-09 19:52 
GeneralRe: Displaying Data fetched asyncronously Pin
Michael Sync23-Jul-09 20:11
Michael Sync23-Jul-09 20:11 
GeneralRe: Displaying Data fetched asyncronously Pin
Adriaan Davel23-Jul-09 21:32
Adriaan Davel23-Jul-09 21:32 
GeneralRe: Displaying Data fetched asyncronously Pin
Michael Sync24-Jul-09 2:23
Michael Sync24-Jul-09 2:23 
GeneralRe: Displaying Data fetched asyncronously Pin
Jeremy Likness26-Jul-09 3:17
professionalJeremy Likness26-Jul-09 3:17 
GeneralRe: Displaying Data fetched asyncronously Pin
Adriaan Davel27-Jul-09 1:42
Adriaan Davel27-Jul-09 1:42 
AnswerRe: Displaying Data fetched asyncronously Pin
Daniel Vaughan9-Jan-10 7:33
Daniel Vaughan9-Jan-10 7:33 
QuestionWPF TreeListView Control Not Working!!!!! Pin
ub3rst4r11-Jul-09 15:01
ub3rst4r11-Jul-09 15:01 
AnswerRe: WPF TreeListView Control Not Working!!!!! Pin
Christian Graus13-Jul-09 7:33
protectorChristian Graus13-Jul-09 7:33 
GeneralRe: WPF TreeListView Control Not Working!!!!! Pin
ub3rst4r13-Jul-09 8:24
ub3rst4r13-Jul-09 8:24 
GeneralRe: WPF TreeListView Control Not Working!!!!! Pin
Christian Graus13-Jul-09 8:42
protectorChristian Graus13-Jul-09 8:42 
QuestionDid you ever wonder, What the origin of XAML is? [modified] Pin
ProtoBytes10-Jul-09 10:29
ProtoBytes10-Jul-09 10:29 
AnswerRe: Did you ever wonder, What the origin of XAML is? Pin
Christian Graus11-Jul-09 4:39
protectorChristian Graus11-Jul-09 4:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.