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

Adding Rows to Grid Programmatically

3 Answers 364 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shoo
Top achievements
Rank 1
Shoo asked on 25 Jun 2016, 05:17 AM

I have a grid that contains a dropdown column as bellow:

GridViewComboBoxColumn type = new GridViewComboBoxColumn();
type.Name = "Type";
type.HeaderText = "Type";
type.ValueMember = "Id";
type.DisplayMember = "Type";
type.DataSource = new string[] {"A", "B", "C"};
type.DropDownStyle = RadDropDownStyle.DropDownList;
grid.Columns.Add(type);

Suppose the user adds two new rows and selects "A" from dropdown for the first row and selects "B" from dropdown for the second row. I don't know how I can save the grid and then load it later. I should say that I know how to use Linq to save data into SQL database, but I don't know how I can get the values that the user selected and how to load data into grid later. Please help me.

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Jun 2016, 09:38 AM
Hello Shoo,

Thank you for writing. 

In order to export the grid data and load it later, I would recommend you to use the ExportToCSV class. Then, you can use the CSV file to fill a DataTable and bind the RadGridView. The following StackOverflow thread demonstrates how to populate a DataTable from a CSV file: http://stackoverflow.com/questions/1050112/how-to-read-a-csv-file-into-a-net-datatable

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Shoo
Top achievements
Rank 1
answered on 28 Jun 2016, 07:15 AM
I cannot use ExportToCSV. I have SQL database and my data is completely dynamic and my data are updated in a network environment
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 28 Jun 2016, 07:46 AM
Hello Shoo,

Thank you for writing back. 

By design, RadGridView doesn't support data import functionality. That is why I suggested you using the CSV format because you can import it in a DataTable and bind the grid to it. Could you please specify in what format exactly your data is stored in the SQL server? Thus, we would be able to think about a possible solution.

I am looking forward to your reply.

Regards,
Dess
Telerik
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
GridView
Asked by
Shoo
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Shoo
Top achievements
Rank 1
Share this question
or