RadGridView issues with dynamic headers/data

2 posts, 0 answers
  1. Vivian
    Vivian avatar
    1 posts
    Member since:
    Jan 2015

    Posted 02 Jan 2015 Link to this post

    Hi Guys, 

    Sorry about bringing up a probably n00b question. 
    I have a string which is in the format of a csv. I have parsed the csv and want to show the contents in a RadGridView. 
    This is what I have done and a bit lost at the moment.

    C#
    //COnstructor accepting string
            public ucCsvEditor(string csv)
            {
                InitializeComponent();
                using (StringReader sr = new StringReader(csv))
                {
                    var reader = new CsvReader(sr);
     
                    //CSVReader will now read the whole file into an enumerable
                    while (reader.Read())
                    {
                        string[] records = reader.CurrentRecord;
                        string[] headers = reader.FieldHeaders;
                        variablesValue.Add(records);
                        variablesHeader.Add(headers);
                    }
                    //ObservableCollection<string[]> myCollection = new ObservableCollection<string[]>(variablesValue);
                    radGridView.ItemsSource = variablesValue;
                    //reader.FieldHeaders
                }
            }

    XAML:
    <Grid>
           <telerik:RadGridView x:Name="radGridView" Grid.Row="0" AutoGenerateColumns="True" IsReadOnly="False" CanUserDeleteRows="False" />
       </Grid>

    I call this GridView from the following code:
    C#
    if (!string.IsNullOrEmpty(csvData))
                {
                    RadWindow winCsvEditor = new RadWindow();
                    ucCsvEditor temp = new ucCsvEditor(csvData);
                    winCsvEditor.Content = temp;
                    winCsvEditor.Header = "CSV Editor";
                    winCsvEditor.Owner = this;
                    winCsvEditor.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
                    winCsvEditor.CanClose = true;
                    winCsvEditor.ShowDialog();
                }
                else
                {
                    MessageBox.Show("No Variables available to edit");
                }

    The output is shown as shown int he attachment. 

    Not exactly the output I was looking for. 
    Since the string[] keeps changing each time I call the GridView depending on the parameters. How do I dynamically build the RadGridView. ?? Any helps is appreciated. 
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 05 Jan 2015 Link to this post

    Hi,

    Does the same approach work fine when populating a DataGrid or a ListBox. You can also check the Loading Data from XML article on how to populate RadGridView. 

    Regards,
    Dimitrina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top