This is a migrated thread and some comments may be shown as answers.

RadGridView issues with dynamic headers/data

1 Answer 123 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vivian
Top achievements
Rank 1
Vivian asked on 02 Jan 2015, 04:04 PM
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. 

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 05 Jan 2015, 02:24 PM
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.

 
Tags
GridView
Asked by
Vivian
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or