Adding only 1st Row of Datagrid with combobox

Dec 15, 2009 at 5:21 PM
Hi,
I am trying to add 1st row of the Datagrid to be one with a mulitpl selection(Combox). The other rows will be will be editable text. I do this by binding to a dataset. If I want an extra column I am able to do it easily by adding a templatedcolumn in the XAML datagrid. 
Is there some way to similarly add row.
P.S(The requirement is to reverse the rows and columns to avoid scrolling).
I have pasted below the sample code.
XAML
<Grid Height="339" Width="697">
        <Label Margin="96,33,379,206">Name:</Label>
        <Label Name="tableName" Content="{Binding Name}"  Margin="143,33,176,267"></Label>
        <Label Margin="67,62,411,238">Reset Action:</Label>
        <ComboBox Height="23" HorizontalAlignment="Left"  Margin="152,62,0,0" ItemsSource="{Binding ResetAction}"  SelectedValue="{Binding Path=ResetAction}"  Name="resetaction"  VerticalAlignment="Top" Width="120" />
        <dg:DataGrid IsReadOnly="False"  Name="tablegrid" AutoGenerateColumns="True"  RowHeight="20" Margin="152,91,58,39">
                                  
        </dg:DataGrid>
        <Button Name="Addbutton" Click="Addbutton_Click" Margin="258,303,378,9">Add</Button>
        <Button Name="Deletebutton" Click="Deletebutton_Click" Margin="0,306,309,9" HorizontalAlignment="Right" Width="53">Delete</Button>
    </Grid>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 Microsoft.SqlServer.Management.Smo;
using System.Collections.ObjectModel;
using System.Data;
using System.ComponentModel; 

namespace TreeViewControlWPF
{
    /// <summary>
    /// Interaction logic for TestTable.xaml
    /// </summary>
    /// 
    public partial class TestTable : UserControl
    {
        public DataSet ds;
        public DataTable datatable;
        int i = 1;
        public TestTable()
        {
            InitializeComponent();
            resetaction.Items.Add(resetAction.clear);
            resetaction.Items.Add(resetAction.noClear);

            

            ds = new DataSet();
            datatable = new DataTable();
            ds.Tables.Add(datatable);
            datatable = addColumn(datatable, "Field");
            datatable = CreateTable(datatable);
            tablegrid.DataContext = ds.Tables[0];
            tablegrid.ItemsSource = (ds.Tables[0] as IListSource).GetList();
            
        }

        private void Deletebutton_Click(object sender, RoutedEventArgs e)
        {

        }
        private DataTable CreateTable(DataTable datatable)
        {
      
            DataRow row;
            string tablename = "Employee";//tableName.DataContext.ToString();
            string SQLServerInstance = " "; //server name
            string DatabaseName = " "; //Database Name
            Server server = new Server();
            server.ConnectionContext.ServerInstance = SQLServerInstance;
            server.ConnectionContext.LoginSecure = true;
            server.ConnectionContext.Connect();
            Database database = new Database(server, DatabaseName);


Microsoft.SqlServer.Management.Smo.Table table = new Microsoft.SqlServer.Management.Smo.Table(database, tablename);
            table.Refresh();

            foreach (Column column in table.Columns)
            {
                row = datatable.NewRow();
                row["Field"] = column.Name;
                datatable.Rows.Add(row);
            }

            return datatable;
        }

    
        private DataTable addColumn(DataTable table, string columnName)
        {
            DataColumn col = new DataColumn(columnName, typeof(string));
            table.Columns.Add(col);
            return table;
        }

        private void Addbutton_Click(object sender, RoutedEventArgs e)
        {
            tablegrid.ItemsSource = null; 
            
            string recordstring="Record";
            recordstring = recordstring + " " + i;         
            datatable = addColumn(datatable,recordstring);           
            i = i + 1;                      
            tablegrid.DataContext = ds.Tables[0];
            tablegrid.ItemsSource = (ds.Tables[0] as IListSource).GetList();            
            
        }
    }
}