How to create column programmatically using WPF Toolkit Datagird?

Jun 21, 2010 at 10:05 AM
Hi, I'm trying to add columns to my grid, but it shows me always the first recort of my SQL Table. What am I doing wrong? DataSet DatSet = new DataSet(); SqlDataAdapter Da = new SqlDataAdapter("Select IdModelo,Modelo from dbo.VRptObterModelos ", ModMain.MyGestCalCnn); Da.Fill(DatSet); //GrdTeste.AutoGenerateColumns = false; GrdTeste.CanUserAddRows = true; GrdTeste.CanUserDeleteRows = true; GrdTeste.Width = 300; Microsoft.Windows.Controls.DataGridTextColumn Txt = new Microsoft.Windows.Controls.DataGridTextColumn(); Txt.Header = DatSet.Tables[0].Columns["Modelo"].ColumnName; Txt.CanUserResize = false; Txt.CanUserReorder = false; Txt.Width = 250; Txt.IsReadOnly = true; Binding x = new Binding(); x.Source = DatSet.Tables[0].DefaultView; x.Path = new PropertyPath(DatSet.Tables[0].Columns["Modelo"].ColumnName); x.Mode = BindingMode.TwoWay; Txt.Binding = x; GrdTeste.Columns.Add(Txt); //GrdTeste.ItemsSource = DatSet.Tables[0].DefaultView; int i = 0; foreach (DataRow r in DatSet.Tables[0].Rows) { TextBox TxtGrid = new TextBox(); TxtGrid.SetBinding(ItemsControl.ItemsSourceProperty, x); TxtGrid.SetValue(Grid.RowProperty, i); //TextBox.TextProperty i++; GrdTeste.Items.Add(TxtGrid); }