How do I fill an MRU list?


Author
Message
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K 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


Replies
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K 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 (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
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.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K 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 (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Cool Cool
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Bill Cunnien - 17 Years Ago
Bill Cunnien - 17 Years Ago
Trent L. Taylor - 17 Years Ago
Bill Cunnien - 17 Years Ago
Trent L. Taylor - 17 Years Ago
                         Excellent! That tip just cut my code in half. Lean and mean! :D...
Bill Cunnien - 17 Years Ago
                             Cool :cool:
Trent L. Taylor - 17 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search