Adding Rows to Grid Programmatically

4 posts, 0 answers
  1. Shoo
    Shoo avatar
    3 posts
    Member since:
    Jun 2016

    Posted 25 Jun Link to this post

    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.

  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 27 Jun Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Shoo
    Shoo avatar
    3 posts
    Member since:
    Jun 2016

    Posted 28 Jun in reply to Dess Link to this post

    I cannot use ExportToCSV. I have SQL database and my data is completely dynamic and my data are updated in a network environment
  5. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 28 Jun Link to this post

    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.
Back to Top