|
Infralution Support Support groups for Infralution products
|
View previous topic :: View next topic |
Author |
Message |
flc.net
Joined: 21 Jun 2005 Posts: 89 Location: Switzerland
|
Posted: Fri Jul 29, 2005 8:05 am Post subject: Find Problems 2 |
|
|
Hello Support
Have you a good idea how I can (easy) resolve my problem?
Remember my last Demo Solution. I extended it a Little bit:
Code: |
dsCars.CompaniesRow fiat = ds.Companies.AddCompaniesRow(1, "Fiat", "Turin Street", "18004", "Turin", "Italy");
dsCars.CompaniesRow bmw = ds.Companies.AddCompaniesRow(2, "BMW", "Frankfurtstrasse", "33440", "Munich", "Germany");
dsCars.CompaniesRow seat = ds.Companies.AddCompaniesRow(3, "Seat", "Via del Toro", "22340", "Madrid", "Spain");
ds.Cars.AddCarsRow(1, "Uno", 100, 10000, fiat);
ds.Cars.AddCarsRow(2, "Panda", 90, 89999, fiat);
ds.Cars.AddCarsRow(3, "Brava", 140, 15000, fiat);
ds.Cars.AddCarsRow(4, "M3", 300, 100000, bmw);
ds.Cars.AddCarsRow(5, "525", 200, 89000, bmw);
ds.Cars.AddCarsRow(6, "Ibiza", 110, 20000, seat);
ds.Cars.AddCarsRow(7, "Malaga", 130, 14000, seat);
ds.Cars.AddCarsRow(8, "Marea", 110, 15500, fiat);
ds.Companies.DefaultView.Sort = "Name";
ds.Cars.DefaultView.Sort = "Model";
ds.AcceptChanges();
|
my Find Functionality:
Code: |
DataRow[] allCars = null;
private void cmdSearch_Click(object sender, System.EventArgs e)
{
allCars = ds.Cars.Select("Model LIKE 'Ma%'");
DataRowView mySearchItem = DataRowRowBinding.GetDataRowView(allCars[0]);
tree.SelectedItem = mySearchItem;
}
private void cmdSearchNext_Click(object sender, System.EventArgs e)
{
DataRowView mySearchItem = DataRowRowBinding.GetDataRowView(allCars[1]);
tree.SelectedItem = mySearchItem;
}
|
my Problem:
Fiat is the second Row
Seat is the thrid Row
Because the Sort of Cars ist set to --> ds.Cars.DefaultView.Sort = "Model"
The Car "Malaga" is the first Row and the Car "Marea" ist the second Row in the "allCars" Array.
But my desired behaviour ist to select first the Car "Marea" because "Fiat" is displayed before "Seat".
My first Idea was to iterate through all Virutal Tree Items. Is that possible or have you a better idea?
Thanks and Best Regards
Giuseppe |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Aug 01, 2005 12:05 am Post subject: |
|
|
This isn't strictly a VirtualTree issue. What you really want is for the Select statement to return you the Car rows sorted by the company and then model. There is an overload of the select method that takes a sort string. Unfortunately I don't think you can specify sorting through a relation - otherwise this might work for you:
Code: |
allCars = ds.Cars.Select("Model LIKE 'Ma%'", "Company.Name, Model");
|
If this doesn't work then you could sort the returned array yourself by implementing your own class that implements the IComparer interface and compares two car rows based on the company name then model. _________________ Infralution Support |
|
Back to top |
|
|
flc.net
Joined: 21 Jun 2005 Posts: 89 Location: Switzerland
|
Posted: Tue Aug 02, 2005 7:36 am Post subject: |
|
|
hi
thanks for your help.
i'm right, that's not possible iterate through all rows in the tree?
best regards
Giuseppe |
|
Back to top |
|
|
flc.net
Joined: 21 Jun 2005 Posts: 89 Location: Switzerland
|
Posted: Tue Aug 02, 2005 9:40 am Post subject: My Generic Workarround |
|
|
The Idea with the IComparer was great. Her's my generic implementation (if someone else have the same needs)
Code: |
public class VirtualTreeRelationComparer : IComparer
{
VirtualTree tree;
public VirtualTreeRelationComparer(VirtualTree tree)
{
this.tree = tree;
}
#region IComparer Members
public int Compare(object x, object y)
{
Row rX = tree.FindRow(DataRowRowBinding.GetDataRowView(x as DataRow));
Row rY = tree.FindRow(DataRowRowBinding.GetDataRowView(y as DataRow));
Row dummyX = null;
Row dummyY = null;
while(rX.ParentRow != null || rY.ParentRow != null)
{
if(rX.ParentRow != null && rY.ParentRow != null)
{
dummyX = rX.ParentRow;
dummyY = rY.ParentRow;
if(dummyX.Equals(dummyY))
{
return rX.RowIndex - rY.RowIndex;
}
rX = dummyX;
rY = dummyY;
}
else
{
return rX.RowIndex - rY.RowIndex;
}
}
// impossible
return 0;
}
#endregion
}
|
Find and FindNext functions
Code: |
DataRow[] allCars = null;
int index = 0;
private void cmdSearch_Click(object sender, System.EventArgs e)
{
allCars = ds.Cars.Select("Model LIKE 'Ma%'");
Array.Sort(allCars, new VirtualTreeRelationComparer(tree));
DataRowView mySearchItem = DataRowRowBinding.GetDataRowView(allCars[0]);
tree.SelectedItem = mySearchItem;
}
private void cmdSearchNext_Click(object sender, System.EventArgs e)
{
DataRowView mySearchItem = DataRowRowBinding.GetDataRowView(allCars[++index]);
tree.SelectedItem = mySearchItem;
}
|
Giuseppe
p.s. I' don't have tested VirtualTreeRelationComparer too much |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|