StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



How do I fill an MRU list?Expand / Collapse
Author
Message
Posted 07/03/2008 8:15:18 AM


Advanced StrataFrame User

Advanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame User

Group: StrataFrame Users
Last Login: Yesterday @ 11:56:54 AM
Posts: 713, Visits: 3,107
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

Post #17583
Posted 07/03/2008 8:29:27 AM


Advanced StrataFrame User

Advanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame User

Group: StrataFrame Users
Last Login: Yesterday @ 11:56:54 AM
Posts: 713, Visits: 3,107
I got the sort issue sorted out.

On the control set the Properties.Sorted = true.  Not sure why that is necessary, but it works.

Post #17585
Posted 07/03/2008 9:28:33 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 2:32:07 PM
Posts: 6,217, Visits: 6,081
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.
Post #17591
Posted 07/03/2008 9:44:24 AM


Advanced StrataFrame User

Advanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame User

Group: StrataFrame Users
Last Login: Yesterday @ 11:56:54 AM
Posts: 713, Visits: 3,107
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

Post #17594
Posted 07/03/2008 9:58:55 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 2:32:07 PM
Posts: 6,217, Visits: 6,081
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...
}

Post #17596
Posted 07/03/2008 11:00:31 AM


Advanced StrataFrame User

Advanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame User

Group: StrataFrame Users
Last Login: Yesterday @ 11:56:54 AM
Posts: 713, Visits: 3,107
Excellent!  That tip just cut my code in half.  Lean and mean! 

Thanks!
Bill

Post #17598
Posted 07/03/2008 11:02:59 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 2:32:07 PM
Posts: 6,217, Visits: 6,081
Cool
Post #17599
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 8:20pm

Powered by InstantForum.NET v4.1.4 © 2010
Execution: 0.141. 10 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.