Custom control for telerik grid view in winforms
In my Windows forms control library:
for MyGrid.cs (where MyGrid.cs is a component class)
public MyGrid : ` Telerik.WinControls.UI.RadGridView`
I build and i have MyGrid.dll & i have added that in my visual studio toolbox (also referenced that dll in my consuming winform app).
Consuming winform app:
1. In Form1.cs, i drag and drop that MyGrid & i write this code:
> MyGrid1.DataSource=ds.Table[0]; //Dataset
The grid doesn't get bound with records, whereas when i check ds `row count it has 150 records`. The grid however shows me green and white color (ie. alternating row color), but doesn't bind the data.
This is the code that consuming winform uses
DataSet ds = null;
string connectionString = "Data Source=test;Initial Catalog=DBname;Integrated Security=True";
string sql = " SELECT ID,FirstName from table1 ";
SqlConnection connection = null;
connnection = new SqlConnection(connectionString);
SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
ds= new System.Data.DataSet();
connection.Open();
dataadapter.Fill(ds, "Table1");
MyGrid1.DataSource = ds.Tables[0];
where MyGrid1 is the custom control that is being dragged and dropped from toolbox.
Custom control code:
this.EnableAlternatingRowColor = true;
this.TableElement.AlternatingRowColor = System.Drawing.Color.Green;
this.MasterTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.AutoGenerateColumns = true;
The telerik grid is not binding the data, however when i click on the cell, it shows me the value. Any thoughts?
In my Windows forms control library:
for MyGrid.cs (where MyGrid.cs is a component class)
public MyGrid : ` Telerik.WinControls.UI.RadGridView`
I build and i have MyGrid.dll & i have added that in my visual studio toolbox (also referenced that dll in my consuming winform app).
Consuming winform app:
1. In Form1.cs, i drag and drop that MyGrid & i write this code:
> MyGrid1.DataSource=ds.Table[0]; //Dataset
The grid doesn't get bound with records, whereas when i check ds `row count it has 150 records`. The grid however shows me green and white color (ie. alternating row color), but doesn't bind the data.
This is the code that consuming winform uses
DataSet ds = null;
string connectionString = "Data Source=test;Initial Catalog=DBname;Integrated Security=True";
string sql = " SELECT ID,FirstName from table1 ";
SqlConnection connection = null;
connnection = new SqlConnection(connectionString);
SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
ds= new System.Data.DataSet();
connection.Open();
dataadapter.Fill(ds, "Table1");
MyGrid1.DataSource = ds.Tables[0];
where MyGrid1 is the custom control that is being dragged and dropped from toolbox.
Custom control code:
this.EnableAlternatingRowColor = true;
this.TableElement.AlternatingRowColor = System.Drawing.Color.Green;
this.MasterTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.AutoGenerateColumns = true;
The telerik grid is not binding the data, however when i click on the cell, it shows me the value. Any thoughts?