Okay, I know I'm missing something here. I'm using the latest version of Rad for WinForms (Q1 2008) and I'm trying to populate a RadGridView using code only (not the BindingSource control). Can you tell me why this code isn't working?
private void PopulateGrid()
{
DataSet ds = GetMasterDetail();
radGridView1.DataSource = ds;
}
private DataSet GetMasterDetail()
{
DataTable master = Clients.GetMasterList();
master.TableName = "Clients";
DataTable child = Orders.GetChildList();
child.TableName = "Orders";
DataSet ds = new DataSet();
ds.Tables.Add(master.Copy());
ds.Tables.Add(child.Copy());
DataRelation relationship = new DataRelation("MasterDetail", ds.Tables["Clients"].Columns["ClientID"], ds.Tables["Orders"].Columns["ClientID"]);
ds.Relations.Add(relationship);
return ds;
}
Why does iterating through the rows in the grid take so long like in this example. It can take a few minutes to walk through every row in the grid if it contains 10000+ rows. Is there a more efficient way to walk the rows. I am trying to implement a find within a column functionality, but it is extremely slow for a large number of rows.
for (int i = 0; i < Global.MainUiForm.OutputGrid.RowCount; i++)
{
currentRow =
Global.MainUiForm.OutputGrid.MasterGridViewInfo.Rows[i];
radColumn = (
RadColumn)this.comboBoxLookIn.SelectedItem;
if (regex.IsMatch(currentRow.Cells[radColumn.FieldName].Value.ToString()))
{
currentRow.IsCurrent =
true;
currentRow.EnsureVisible();
currentRow.Cells[radColumn.FieldName].EnsureVisible();
found =
true;
break;
}
}
public class Client |
{ |
public int ID { get; set; } |
public string Name { get; set; } |
public Client(int id, string name) |
{ |
ID = id; |
Name = name; |
} |
} |
public class Order |
{ |
public int ID { get; set; } |
public int ClientID { get; set; } |
public int Quantity { get; set; } |
public Order(int id, int clientid, int quantity) |
{ |
ID = id; |
ClientID = clientid; |
Quantity = quantity; |
} |
} |
public class OrderPrices |
{ |
public int ID { get; set; } |
public int ClientID { get; set; } |
public double Price { get; set; } |
public OrderPrices(int id, int clientid, double price) |
{ |
ID = id; |
ClientID = clientid; |
Price = price; |
} |
} |
private void Form1_Load(object sender, EventArgs e) |
{ |
radGridView1.AutoGenerateHierarchyFromDataSet = false; |
ordersTemplate = new GridViewTemplate(this.radGridView1); |
radGridView1.MasterGridViewTemplate.ChildGridViewTemplates.Add(ordersTemplate); |
GridViewRelation relation1 = new GridViewRelation(this.radGridView1.MasterGridViewTemplate); |
relation1.RelationName = "Clients Orders1"; |
relation1.ParentColumnNames.Add("ID"); |
relation1.ChildColumnNames.Add("ClientID"); |
relation1.ChildTemplate = ordersTemplate; |
radGridView1.Relations.Add(relation1); |
orderPricesTemplate = new GridViewTemplate(radGridView1); |
radGridView1.MasterGridViewTemplate.ChildGridViewTemplates.Add(orderPricesTemplate); |
GridViewRelation relation2 = new GridViewRelation(radGridView1.MasterGridViewTemplate); |
relation2.RelationName = "Clients Order Prices"; |
relation2.ParentColumnNames.Add("ID"); |
relation2.ChildColumnNames.Add("ClientID"); |
relation2.ChildTemplate = orderPricesTemplate; |
radGridView1.Relations.Add(relation2); |
LoadData(); |
} |
private void LoadData() |
{ |
BindingList<Client> clients = new BindingList<Client> |
{ |
new Client(1, "John Smith"), |
new Client(2, "Peter Jackson"), |
new Client(3, "Samuel Dell"), |
new Client(4, "Test") |
}; |
BindingList<Order> orders = new BindingList<Order> |
{ |
new Order(1, 1, 2), |
new Order(1, 1, 1), |
new Order(1, 2, 10), |
new Order(1, 3, 43) |
}; |
BindingList<OrderPrices> orderprices = new BindingList<OrderPrices> |
{ |
new OrderPrices(1, 4, 1.50), |
new OrderPrices(1, 4, 9.99), |
new OrderPrices(1, 1, 10.11), |
new OrderPrices(1, 2, 43.42) |
}; |
orderPricesTemplate.DataSource = orderprices; |
ordersTemplate.DataSource = orders; |
radGridView1.DataSource = clients; |
} |