MarkItZero Posted July 21, 2004 Posted July 21, 2004 I am kind of stumped right now and I am hoping for some ideas. Here is the situation. I created a windows program to manage the dispatching of our delivery drivers. The program uses an Access database to hold the data. Each day the users will enter several new dispatch entries on the DispatchDetails form. They are also able to view existing entries on this same form. Included on the form are combo boxes containing information such as DriverName, Truck, Trailer# and LoadSize. Here is the code is use to populate the CmboDriver 'Clear Dataset DsDetDrivers1.Clear() 'Fill Dataset OleDbDataAdapter8.Fill(DsDetDrivers1, "Drivers") 'Datarow Dim DRDriver As DataRow 'Declare Array Dim ArryDriver As ArrayList = New ArrayList() 'Fill Array For Each DRDriver In DsDetDrivers1.Tables("Drivers").Rows If DRDriver("Inactive") <> True Then ArryDriver.Add(New LookupItem(DRDriver("DriverID"), DRDriver("DriverName").ToString())) End If Next 'Bind and Show Cmbo Box CmboDriver.DataSource = ArryDriver CmboDriver.DisplayMember = "Text" CmboDriver.ValueMember = "ID" CmboDriver.DropDownStyle = ComboBoxStyle.DropDownList CmboDriver.Show() CmboDriver.SelectedValue = DRDispatchDetails("DriverID") The code for the other combo boxes are essentially identical. As you can see, I check the Inactive field in the driver table to make sure I only display active drivers in the combo box. That way a user will be unable to select an inactive driver for a new entry. However, because users can open, view and edit existing entries, I need to be able to display the drivers name even if the driver has since been inatcivated. So, I guess what I need is to find a way to check to see if my driver is inactive, and if he is, then I need to populate the combobox with all of the active drivers + the current driver. Sorry for the long post. I hope that makes sense. And ideas will be greatly appreciated. Thanks! Quote
*Experts* Nerseus Posted July 25, 2004 *Experts* Posted July 25, 2004 We've done something similar. For us, our If test on whether to add an item to a combo was changed to filter out inactive items unless it was the current value (driver in your case). Also, I'd change your loop to do a Select and loop through the filtered rows. Here's a code snippet to do both: Dim MatchingRows() As DataRow() = DsDetDrivers1.Tables("Drivers").Select("Inactive = False OR DriverID = " + myDriverID) For Each DRDriver In MatchingRows ' No need to do the following check anymore - filtered above ' If DRDriver("Inactive") <> True Then ArryDriver.Add(New LookupItem(DRDriver("DriverID"), DRDriver("DriverName").ToString())) ' End If Next In the above, myDriverID would be set to the one you want to include even if it's inactive. Another option is to use a new custom object, similar to your LookupItem class, but on that includes the Inactive flag as a property. When trying to select anyone from the combo for editing, you could run code that checks the Inactive propert and disables the "Edit" button (or maybe display a message if they try to edit them). -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
MarkItZero Posted July 27, 2004 Author Posted July 27, 2004 Thank you very much! I will test it out. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.