I am new to GridView control for Windows Application.
I have some doubts.
How to apply theme to a Grid View.
Problem I am facing: When I apply themes to grid,outer border are disapperaing and + symbol for expanding and collapsing Hierarchial grid is changing to some different control.Its make my grid looks odd.
How to set a GridView in Unbound Mode.
Which one will be the default mode for GridView.
Thanks,
A2H
4 Answers, 1 is accepted
These links should help.
The first one is for RadGridView in Unbound Mode
And this one tell you about theming the RadGridView
Which theme are you using that looks odd? If you follow the tutorial and have further issues, let me know. If you can post a screenshot of the issue, that would be great.
Thanks
Richard
Hi,
I have followed your hyperlink for Grid View in Unbound mode.
Its help to populate the data in Master Grid.
But For Child Grid I am facing one issue.I have modified the code in the hyperlink according to my scenario.
private
void LoadUnboundData()
{
DataTable dttable1 = populateMasterGrid();
DataTable dttable2 = populateChildGrid();
GridViewTemplate template = radgridview1.MasterGridViewTemplate.ChildGridViewTemplates[0];
for (int i = 0; i < dttable1 .Rows.Count; i++)
{
radgridview1.MasterGridViewTemplate.Rows.Add(dttable1 .Rows[i].ItemArray[0].ToString(), dttable1 .Rows[i].ItemArray[1].ToString(), dttable1 .Rows[i].ItemArray[2].ToString(),
dttable1 .Rows[i].ItemArray[3].ToString(), dttable1 .Rows[i].ItemArray[4].ToString());
string strExpr;
// Setup Filter
strExpr =
"dttable2value= " + dttable1 .Rows[i].ItemArray[0].ToString();
DataRow[] dRow = dttable2 .Select(strExpr);
for (int j = 0; j < dRow.Count(); j++)
{
template.Rows.Add(dttable2 .Rows[i].ItemArray[0].ToString(), dttable2 .Rows[i].ItemArray[1].ToString(), dttable2 .Rows[i].ItemArray[2].ToString(), dttable2 .Rows[i].ItemArray[3].ToString());
}
}
}
Here the problem I am facing is duplicates values are getting populated in child grid.
Please help what I doing wrong over here.
Many Thanks,
A2H
Thanks
Richard
Please see this example of using UnboundMode:
using System.Data;using System.Windows.Forms;using Telerik.WinControls.UI;public partial class Form1 : Form{ private RadGridView radGridView1; public Form1() { InitializeComponent(); this.radGridView1 = new RadGridView(); this.Controls.Add(radGridView1); this.radGridView1.Dock = DockStyle.Fill; this.radGridView1.ReadOnly = false; this.radGridView1.AllowAddNewRow = true; this.radGridView1.AutoGenerateHierarchy = true; var column = new GridViewDecimalColumn("Id"); radGridView1.MasterTemplate.Columns.Add(column); GridViewTextBoxColumn textColumn = new GridViewTextBoxColumn("Name"); textColumn.Width = 150; radGridView1.MasterTemplate.Columns.Add(textColumn); //setup the child template GridViewTemplate template = new GridViewTemplate(); template.AllowAddNewRow = true; template.Columns.Add(new GridViewDecimalColumn("Id")); template.Columns.Add(new GridViewDecimalColumn("ParentId")); template.Columns.Add(new GridViewTextBoxColumn("Name")); template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; radGridView1.MasterTemplate.Templates.Add(template); //create the relation GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate); relation.ChildTemplate = template; relation.RelationName = "ParentChild"; relation.ParentColumnNames.Add("Id"); relation.ChildColumnNames.Add("ParentId"); radGridView1.Relations.Add(relation); radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; LoadUnboundData(); } private void LoadUnboundData() { DataTable dttable1 = PopulateMasterGrid(); DataTable dttable2 = PopulateChildGrid(); GridViewTemplate childTemplate = radGridView1.MasterTemplate.Templates[0]; for (int i = 0; i < dttable1.Rows.Count; i++) { radGridView1.Rows.Add(dttable1.Rows[i].ItemArray[0], dttable1.Rows[i].ItemArray[1]); var strExpr = "ParentId= " + dttable1.Rows[i].ItemArray[0]; DataRow[] dRow = dttable2.Select(strExpr); for (int j = 0; j < dRow.Length; j++) { childTemplate.Rows.Add(dttable2.Rows[i].ItemArray[0], dttable2.Rows[i].ItemArray[1], dttable2.Rows[i].ItemArray[2]); } } } private DataTable PopulateMasterGrid() { var table = new DataTable(); table.Columns.Add("Id"); table.Columns.Add("Name"); for (int i = 0; i < 10; i++) { var row = table.NewRow(); row[0] = i; row[1] = "Name" + i; table.Rows.Add(row); } return table; } private DataTable PopulateChildGrid() { var table = new DataTable(); table.Columns.Add("Id"); table.Columns.Add("ParentId"); table.Columns.Add("Name"); for (int i = 0; i < 10; i++) { var row = table.NewRow(); row[0] = i + 10; row[1] = i; row[2] = "ChildName" + i; table.Rows.Add(row); } return table; }}This works as expected, 1 child / row.
I'm guessing that there is somewhere a problem in the populateChildGrid method, duplicates are somehow created there?
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga