Home Forums WPF controls Xceed DataGrid for WPF Grouping doesn’t work

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25525 |

    Hi,
    I developed coding for Grouping in code behind(C#) using DatagridCollectionViewSource, actually I added data using List<string> instead of taking from database, but it doesn’t work.

    Can anyone provide code for Grouping(4 level) in Code behind(C#), using List<string> to adding data to Datagrid instead of from database.Also each level should have seperate Header.

    Any reply from Xceed?
    Thanks in advance.

    Imported from legacy forums. Posted by kesavan (had 2400 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Kesavan,

    Data binding with List<String> and DataGridCollectionViewSource + Grouping works fine for me…

    I suggest you post your code on the forums so that fellow community members can help you find the problems in your code.

    Concerning the “Any reply from Xceed?” question. This community forum is dedicated to the Express ( free DataGrid ) subscribers and Xceed’s support team does not monitor it. If you require answers from the support team, I suggest considering upgrades to your subscription.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 242 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanx Marcus.

    This is my code.In this code the Grouping doesn’t work.Please send me the corrected code.

    XAML code

    <UserControl x:Class=” MyNamespace. DataGridTreeView “
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;
    Width=”1280″ Height=”512″ FontFamily=”Verdana” FontSize=”16″ >

    <WrapPanel x:Name=”MainPanel”>
    <Grid xmlns:xcdg=”http://schemas.xceed.com/wpf/xaml/datagrid”&gt;
    <xcdg:DataGridControl xmlns:xcdg=”http://schemas.xceed.com/wpf/xaml/datagrid&#8221;
    x:Name=”grid” Height=”512″ Width=”1280″
    AutoCreateColumns=”False” FontSize=”14″>

    <xcdg:DataGridControl.View >
    <xcdg:TableView Name =”tblView”>

    <xcdg:TableView.FixedHeaders>
    <xcdg:ClearHeadersFooters/>

    <DataTemplate>
    <xcdg:ColumnManagerRow AllowSort=”True” AllowColumnReorder=”false”/>
    </DataTemplate>

    </xcdg:TableView.FixedHeaders>
    </xcdg:TableView>
    </xcdg:DataGridControl.View>
    </xcdg:DataGridControl>
    </Grid>
    </WrapPanel>
    </UserControl>

    C# code behind

    using Xceed.Wpf.DataGrid;
    using System.Globalization;

    namespace MyNamespace
    {

    public partial class DataGridTreeView
    {
    #region Constuctor
    public DataGridTreeView ( )
    {
    InitializeComponent ( );
    SetupHeader ( );
    UpdateGridView ( );
    }
    #endregion

    #region Methods
    private void SetupHeader()
    {
    this. grid.Columns.Clear ( );
    for ( int i = 0 ; i < header.Length ; i++ )
    {
    Binding bin = new Binding ( );
    string path = “[” + i.ToString ( ) + “]”;
    bin.Path = new PropertyPath ( path, header );
    Column col = new Column ( path, header[i], bin );
    col.Width = widths[i];
    this. grid.Columns.Add ( col );
    }
    }
    private void UpdateGridView ( )
    {
    MyData = new List<string[]>();

    string[] items = new string[header.Length];
    items[0] = “XYZ”;
    items[1] = “1”;
    items[2] = “11/02/78”;
    items[3] = “12/11/07”;
    items[4] = “11:10”;

    MyData.Add ( items );

    Binding dataBind = new Binding ( );
    dataBind.Source = MyData;
    dataBind.Mode = BindingMode.Default;
    dataBind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
    this. grid.SetBinding ( DataGridControl.ItemsSourceProperty, dataBind );

    //Logic
    dd = new DataGridGroupDescription();
    ci = new CultureInfo ( 1 );
    dd.PropertyName = “Name”;
    object value = dd.GroupNameFromItem ( items, 0, ci );

    dg = new DataGridCollectionViewSource ( );
    value = dg.GroupDescriptions;
    dg.Source = value;

    }
    #endregion

    #region Fields
    int[] widths = new int[] { 200, 170, 170, 170, 170};
    string[] header = new string[] { “Name”, “ID”, “Date of Birth”, “Date”, “Time” };
    private List<string[]> MyData;
    private CultureInfo ci;
    private DataGridCollectionViewSource dg;
    private DataGridGroupDescription dd;
    #endregion
    }
    }

    Regards,
    K.Kesavan

    Imported from legacy forums. Posted by kesavan (had 3499 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.