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

get data from dataset

2 Answers 170 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 21 Oct 2012, 02:50 PM
I've created dataset using 'Add new Data source' - ShoppingMallDataSet
Then I what to get data from table TClient. So I've created global variable BindingSource bs and initialize it in method GetData

void GetData(){
using(ShoppingMallDataSet smds = new ShoppingMallDataSet())
            {
                using (var conn = new SqlConnection(connection_string))
                {
                    using (var adapter = new ShoppingMallDataSetTableAdapters.TClientTableAdapter() { Connection = conn })
                    {
                        adapter.Fill(smds.TClient);
                        bs.DataSource = smds.TClient;
                    }
                }
}

and here its using in code
.....
rgv.MasterTemplate.DataSource = bs;
 
GetData();

DataSource is not null but rgv has neither rows no columns. Where is the problem?

2 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 23 Oct 2012, 01:18 PM
Hello Jei,

Thank you for writing.

I have tested the reported scenario and I did not find an issue with RadGridView binding to BindingSource component, which is loaded with data at the end. Here is an example:
using System.Data;
using System.Windows.Forms;
using Telerik.WinControls.UI;
 
namespace Lab.Grid
{
    public partial class GridBindToBindingSource : Form
    {
        private RadGridView gridView = new RadGridView();
        private BindingSource bindingSource = new BindingSource();
 
        public GridBindToBindingSource()
        {
            InitializeComponent();
 
            gridView.Dock = DockStyle.Fill;
            gridView.Parent = this;
            gridView.DataSource = this.bindingSource;
 
            DataTable table = new DataTable();
            table.Columns.Add("Id");
            table.Columns.Add("Name");
 
            for (int i = 0; i < 10; i++)
            {
                table.Rows.Add(i, "Name" + i);
            }
 
            this.bindingSource.DataSource = table;
        }
    }
}

Please refer to the attached screenshot, where you can see the result on my end. If you continue to experience the same issues, please send us some part of your data and a sample application that demonstrates the used loading mechanism to investigate the issues locally and find best solution for your application.  

Thank you for your time and cooperation. 

Greetings,
Julian Benkov
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
0
Sam
Top achievements
Rank 1
answered on 23 Oct 2012, 05:06 PM
                                                                                                                                                                                                                        I've solved the problem. There wasn't any colums or rows until I added RadGridView to controls. After that - on the next line debugger showed that columns count is correct.
Tags
GridView
Asked by
Sam
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Sam
Top achievements
Rank 1
Share this question
or