How do I fill an MRU list?


Author
Message
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
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


Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I got the sort issue sorted out. Smile

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

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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.
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
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

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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...
}


Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Excellent!  That tip just cut my code in half.  Lean and mean!  BigGrin

Thanks!
Bill

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Cool Cool
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search