Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. How can I have multiple datasources in the same datagridview combo column [modified]

How can I have multiple datasources in the same datagridview combo column [modified]

Scheduled Pinned Locked Moved Windows Forms
databasehelpquestionc++css
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Ger Hayden
    wrote on last edited by
    #1

    In the 24 hours since my original post I have made no progress and huge progress. None in that the problem persists, but I have learned volumes about how the combo column behaves. Here is my original post: My application reads bus routes into a combo column on a datagrid view. For each Route the Stages column is reloaded. Each Passenger on Route 1 has its correct stage displayed, but the grid fails to show the stages for passengers on Route 2. When I step through the code, I can see the Stage column reload and the correct stage picked from the list for Route 2, but its never shown. Not only that, it throws in the Datagrid View Default Error Dialog for good measure. I am using VS2008, C++/CLI grid is entirely unbound and I am not employing datasoures, so setting displaymember/valuemember is not available to me. void VTPassenger::frmPassengerMaster::Load_RouteStages(int arg_Route_ID) { dgStage->Items->Clear(); dgStage->Items->Add("0 <--- Undefined --->"); // then the Stages for this Route List<CRouteStage^>^ RouteStageList = gcnew List<CRouteStage^>(); try { RouteStageList = CComs_RS::Fetch_RouteStage(m_LocalConnection,1,arg_Route_ID); } catch(Exception ^e) { String ^MessageString = " SQL Error retrieving Route Stages: " + e->Message; MessageBox::Show(MessageString, "RouteStage Techincal Error"); return; } if (RouteStageList->Count == 0)// No records so no Ticket types defined { return; } for each(CRouteStage^ candidate in RouteStageList) { array<Object^>^ itemRec = gcnew array<Object^> {candidate->p_Stage_ID, candidate->p_StageName }; String^ AddString; AddString = String::Format("{0} - {1}", candidate->p_Stage_ID, candidate->p_StageName); this->dgStage->Items->Add(AddString); } } And now for the progress. This will work very well as is if the passenger list is sorted in route order, but do not consider this a suitable workaround. Learning that forced me to reflect on the design. For five hundered passengers distributed over a pair of short routes, 500 database visits doesnt make sense for essentially the same route stages - but what if there were 300 routes involved for our little outfit? Then front loading and holding 300 sets of route stages in a collection in memory doesn't sit well. So programmatically I have created a datatable and read in my route stages upon which I attempted a filter in the sytle of spidernet

    R 1 Reply Last reply
    0
    • G Ger Hayden

      In the 24 hours since my original post I have made no progress and huge progress. None in that the problem persists, but I have learned volumes about how the combo column behaves. Here is my original post: My application reads bus routes into a combo column on a datagrid view. For each Route the Stages column is reloaded. Each Passenger on Route 1 has its correct stage displayed, but the grid fails to show the stages for passengers on Route 2. When I step through the code, I can see the Stage column reload and the correct stage picked from the list for Route 2, but its never shown. Not only that, it throws in the Datagrid View Default Error Dialog for good measure. I am using VS2008, C++/CLI grid is entirely unbound and I am not employing datasoures, so setting displaymember/valuemember is not available to me. void VTPassenger::frmPassengerMaster::Load_RouteStages(int arg_Route_ID) { dgStage->Items->Clear(); dgStage->Items->Add("0 <--- Undefined --->"); // then the Stages for this Route List<CRouteStage^>^ RouteStageList = gcnew List<CRouteStage^>(); try { RouteStageList = CComs_RS::Fetch_RouteStage(m_LocalConnection,1,arg_Route_ID); } catch(Exception ^e) { String ^MessageString = " SQL Error retrieving Route Stages: " + e->Message; MessageBox::Show(MessageString, "RouteStage Techincal Error"); return; } if (RouteStageList->Count == 0)// No records so no Ticket types defined { return; } for each(CRouteStage^ candidate in RouteStageList) { array<Object^>^ itemRec = gcnew array<Object^> {candidate->p_Stage_ID, candidate->p_StageName }; String^ AddString; AddString = String::Format("{0} - {1}", candidate->p_Stage_ID, candidate->p_StageName); this->dgStage->Items->Add(AddString); } } And now for the progress. This will work very well as is if the passenger list is sorted in route order, but do not consider this a suitable workaround. Learning that forced me to reflect on the design. For five hundered passengers distributed over a pair of short routes, 500 database visits doesnt make sense for essentially the same route stages - but what if there were 300 routes involved for our little outfit? Then front loading and holding 300 sets of route stages in a collection in memory doesn't sit well. So programmatically I have created a datatable and read in my route stages upon which I attempted a filter in the sytle of spidernet

      R Offline
      R Offline
      RobCroll
      wrote on last edited by
      #2

      If users rarely make a selection from the combo then only request the data when the user edits the cell. This may or may not be acceptable. You may also want to cache the results in a HashTable (route, collection of stages) so before you request the data, see if it already exists in the HashTable. If so, you will be able to access the data in the HashTable and avoid the round trip to the DB.

      G 1 Reply Last reply
      0
      • R RobCroll

        If users rarely make a selection from the combo then only request the data when the user edits the cell. This may or may not be acceptable. You may also want to cache the results in a HashTable (route, collection of stages) so before you request the data, see if it already exists in the HashTable. If so, you will be able to access the data in the HashTable and avoid the round trip to the DB.

        G Offline
        G Offline
        Ger Hayden
        wrote on last edited by
        #3

        Thanks Robert. I found an example that is very similar to your second suggestion. See my next post for details on how I applied it. Ger

        Ger

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups