We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Stacking data in columns

Currently I have my datagrid pulling and assigning data to each columns separately. Lets say I have 4 columns, I want to be able to have the data in column 1 equal column 1 and column 2 stacked. 

MainPage.xmal
<Page.DataContext>
        <local:vmCustomers />
</Page.DataContext>

<Grid:SfDataGrid x:Name="dgCustomers"
                           AutoGenerateColumns="False"
                           ScrollViewer.HorizontalScrollMode="Auto" 
                           ScrollViewer.VerticalScrollMode="Auto"
                           NavigationMode="Row"
                           ItemsSource="{Binding Customers}" Margin="0,137,0,0">
            <Grid:SfDataGrid.Columns>
                <Grid:GridTextColumn ColumnSizer="SizeToHeader" HeaderText="Customer Number" MappingName="custNumber" />
                <Grid:GridTextColumn ColumnSizer="SizeToCells" TextWrapping="NoWrap" HeaderText="Customer Name" MappingName="custName" />
                <Grid:GridTextColumn ColumnSizer="SizeToCells" TextWrapping="NoWrap" HeaderText="Address" MappingName="custAdd1" />
                <Grid:GridTextColumn ColumnSizer="SizeToCells" TextWrapping="NoWrap" HeaderText="Address 1" MappingName="custAdd2" />                
            </Grid:SfDataGrid.Columns>
</Grid:SfDataGrid>

vmCustomers.cs

public class vmCustomers
    {
        private ObservableCollection<dmCust> _customers;
        public ObservableCollection<dmCust> Customers
        {
            get { return _customers; }
            set { _customers = value; }
        }

        public string TMNumber { get; private set; }

        public vmCustomers()
        {            
            _customers = new ObservableCollection<dmCust>();
            this.GenerateOrders();
        }

        
        private async void GenerateOrders()
        {
            
            var path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "cust.db");

            using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path))
            {
                
                var custQry = from p in conn.Table<cust>()
                              where p.CMRP1 == DataClass.tmNumber
                              select new
                              {
                                  CustomerID = p.ID,
                                  CustomerNumber = p.CMCSNO,
                                  CustomerName = p.CMCSNM,
                                  CustomerAddress = p.CMCAD1,
                                  CustomerAddress2 = p.CMCAD2,
                                  
                              };
                try
                {
                    foreach (var d in custQry)
                    {
                        _customers.Add(new dmCust(d.CustomerID, d.CustomerNumber, d.CustomerName, d.CustomerAddress, d.CustomerAddress2, ));
                        int cnt = 0;
                        cnt++;
                        System.Diagnostics.Debug.WriteLine(cnt);                        
                    }
                    
                }
                catch
                {
                    var dialog = new MessageDialog("You must perform a database sync");
                    await dialog.ShowAsync();
                }


            }
            
        }

       
    }

3 Replies

SR Sivakumar R Syncfusion Team May 12, 2016 04:04 PM UTC

Hi Garling, 
 
Your requirement can be achieved using GridTemplateColumn or GridColumn.CellTemplate. Please find the UG link for the same, 
 
You can change the row height also if needed. Please find the documentation link below, 
 
Please let us know if you have any queries. 
 
Thanks, 
Sivakumar 



GB Garling Beard May 12, 2016 07:31 PM UTC

Thank you, that was what I needed. 


SV Srinivasan Vasu Syncfusion Team May 13, 2016 03:36 AM UTC

Hi Garling, 
  
Thanks for your update. 
  
Regards, 
Srinivasan 


Loader.
Live Chat Icon For mobile
Up arrow icon