| | | 
StrataFrame User
       
Group: StrataFrame Users Last Login: 11/25/2008 7:55:39 AM Posts: 473, Visits: 1,955 |
| I have dropped a DevEx MRUEdit control onto a form for the first time. Cool little control. I want to fill this thing with a distinct list of part descriptions. Here is my working code for your review:private void FillPartDescriptionMRU() { // get the distinct list of part descriptions SqlConnection cn = new SqlConnection(MicroFour.StrataFrame.Data.DataLayer.DataSources["Aspire"].ConnectionString); SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cmd.CommandType = CommandType.Text; ADUserBO mADUser = new ADUserBO(); SqlParameter pDiv = new SqlParameter("@division", mADUser.LocationIndex); cmd.Parameters.Add(pDiv); cmd.CommandText = "SELECT DISTINCT partdesc FROM PartsMaster WHERE (divisionindex = @division) AND (inactive = 0) ORDER BY partdesc"; SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); sda.Fill(ds); foreach (DataRow dr in ds.Tables[0].Rows) { txtPartDesc.Properties.Items.Add((string)dr[0]); } }Is this the best way to approach a distinct list of strings from my database in order to fill my MRU list? I do have a PartsBO...is there a way to get these strings from the BO? Also, the list is filled in descending alphabetical order, even though I have specified an ASC sort in the query. Is there a reason why my sort is backwards? Thanks for any help on this!! Bill |
| | | | 
StrataFrame User
       
Group: StrataFrame Users Last Login: 11/25/2008 7:55:39 AM Posts: 473, Visits: 1,955 |
| I got the sort issue sorted out.  On the control set the Properties.Sorted = true. Not sure why that is necessary, but it works. |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Yesterday @ 7:08:30 PM Posts: 4,811, Visits: 4,781 |
| | Glad you got it...we take an entirely different approach to MRUs within our applications. Depending upon where and what are are doing, we may use a combo. But in other cases we use a ListView on a "Getting Started" page. But this really isn't my point on th topic...we actually serialize and store the MRU information on a per user basis in the SQL database itself. This way when a user goes from one machine to the next, their MRUs are still there. Additionaly, we have a single column to query for the user and object state type. We have a MRU base class that we inherit and create for each type of MRU that may need to be created (i.e. patients, codes, templates, etc.) We then serialize the MRU collection to a VarBinary field in an ObjectStates table. So when a user gets to a certain combo/list/whatever, the MRU specifically for them is retrieved and the populates the object in question from the serialized object model. These are just some ideas I thought I would throw out there since you brought up an MRU...this has been a huge hit...especially since it is by user and not specific to a machine. |
| | | | 
StrataFrame User
       
Group: StrataFrame Users Last Login: 11/25/2008 7:55:39 AM Posts: 473, Visits: 1,955 |
| | Nice approach. I'll have to digest some of the details a bit. I only have the one textbox that I have been asked to supply a MRU-type list. The users wanted to pick from all of the decriptions that are on file so that they can be consistent in their naming. What I have provided on this one control works; however, it just seems clumsy to me. Well, I may re-approach this topic if other users start requesting the same thing. Two last thoughts...1) Could my code be streamlined any? I am not that great at manipulating datasets and collections; and, 2) I'd like to refill this list whenever a record is added/deleted/changed. Code I put the code in the AfterSave() method and it would work for all three operations? Thanks a ton! Bill |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Yesterday @ 7:08:30 PM Posts: 4,811, Visits: 4,781 |
| Actually, you really never need to create a connection object. You could reduce your code by just talking straight to the DAL itself://-- Establish Locals SqlCommand cmd; DataTable results; //-- Create the command cmd = new SqlCommand("SELECT DISTINCT partdesc FROM PartsMaster WHERE divisionindex = @division AND inactive = 0 ORDER BY partdesc"); //-- Create the parms cmd.Parameters.AddWithValue("@division", mADUser.LocationIndex).SqlDbType = System.Data.SqlDbType.Int; //-- Execute the query and get the results results = MicroFour.StrataFrame.Data.DataBasics.DataSources[""].GetDataTable(cmd, Nothing); //-- Now cycle through and populate the combo foreach (DataRow row in results.Rows) { //-- populate the combo with the row... } |
| | | | 
StrataFrame User
       
Group: StrataFrame Users Last Login: 11/25/2008 7:55:39 AM Posts: 473, Visits: 1,955 |
| Excellent! That tip just cut my code in half. Lean and mean!  Thanks! Bill |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Yesterday @ 7:08:30 PM Posts: 4,811, Visits: 4,781 |
| Cool |
| |
|
|