Olukayode Oluwole
asked on
Can i use the same method to load a list and datagrid with the same data
I have a List and a Grid i need to fill from my database with the same information
The constructor for the JobHistoryModel is shown below:
public string StaffVariationList
{
get
{
return $" {Staff_no} {Companyname} {DesignationID} {YearsExp} { Startdate } { Enddate} {Companycode}";
}
}
The script below fills the list (see attached screen)
List<JobHistoryModel> variations = GlobalConfig.Connection.Ge tJobHistor yRecords() ;
var data = (sender as ListBox).SelectedValue as EmployeeModel;
StaffJobHistoryList.DataSo urce = variations.Where(variation => data.Staff_no.Equals(varia tion.Staff _no)).ToLi st();
variations = variations.OrderBy(x => x.Staff_no).ThenBy(x => x.DesignationID).ToList();
Is it possible for me to do a script similar to above for the Grid or i need to use a different Method
to load the Grid
Olukay
The constructor for the JobHistoryModel is shown below:
public string StaffVariationList
{
get
{
return $" {Staff_no} {Companyname} {DesignationID} {YearsExp} { Startdate } { Enddate} {Companycode}";
}
}
The script below fills the list (see attached screen)
List<JobHistoryModel> variations = GlobalConfig.Connection.Ge
var data = (sender as ListBox).SelectedValue as EmployeeModel;
StaffJobHistoryList.DataSo
variations = variations.OrderBy(x => x.Staff_no).ThenBy(x => x.DesignationID).ToList();
Is it possible for me to do a script similar to above for the Grid or i need to use a different Method
to load the Grid
Olukay
ASKER
Sounds interesting. I will try this out and get back . When doing this first query where do you
suggest i keep the records since this can not be the list or grid i want to populate.
Olukay
suggest i keep the records since this can not be the list or grid i want to populate.
Olukay
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for being always helpful
Olukay
Olukay
If you're not talking about a large or frequently changing dataset then it will work just fine. Otherwise you're going to want to work in a mechanism for periodically refreshing the collection.
I assume this has a WPF or WinForms front end so it'll be easy to implement.
1. Add a protected List<JobHistoryModel> property to your form's logic code. Let's call it Variations (just for ease of reference; you can call it what you want).
2. When the form loads, perform the "master" query and use the results to fill Variations. You should also populate the ListView at this point.
3. In the ListView event (SelectionChanged?), get the Staff_No of the record and use it to query Variations. Use that query result as the datasource for the Grid.
Have fun!