dcsimg
Results 1 to 5 of 5

Thread: [RESOLVED] Grid doesn't exception with a lot of rows, then I filter and it exceptions with less

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room trying to forget the past
    Posts
    4,087

    Resolved [RESOLVED] Grid doesn't exception with a lot of rows, then I filter and it exceptions with less

    I don't understand this problem I am having. I am binding a data grid to the results of a stored procedure. That works perfectly.

    Then I started to add a a filter. Namely, every row has a "customer service employee" and we want to filter and see only particular employees.

    The first strange thing that happened is columns that were populated when I ran the stored procedure were displaying blank data when I filtered. The pattern I noticed was these were columns that, in the sproc, I was doing a "select ... AS [name with a space]". I changed it to [namewithoutaspace] and that fixed that.

    Now, I am exceptioning with a data-can't-be-null error. If the data coming back from the stored procedure can be null why can't the filter allow it? That is, if I am returning 50 rows from the sproc and they display fine, then I am asking the grid to display 5 of those 50, why would it exception??? It's the same data that it just had no problem with, but less of it!!!

    The grid I am using is a GridView from DevExpress. I am using typed datasets. Here is the code I believe is relevant.
    Code:
            private void PopulateCombined()
            {
                tabsCreated |= TabsCreated.Combined;
    
                using (ForecastTableAdapters.xsp_TableAdapter taCombined = new ForecastTableAdapters.xsp_TableAdapter())
                {
                    dtCombined = new Forecast.xsp_DataTable();
                    taCombined.Fill(dtCombined);
                    gcCombined.DataSource = dtCombined;
                }
    
                PopulateCSEmps();
            }
    
            private void PopulateCombined(string csEmp)
            {
                string sFilter = String.Format("CSEmp = '{0}'", lkupCSEmp.EditValue);
                string sSort = "";
                DataRow[] filteredRows = dtCombined.Select(sFilter, sSort);
                gcCombined.DataSource = filteredRows;
            }
    Am I not seeing something obviously stupid? I don't want to have to rewrite the stored procedure and be calling it several times over as the user changes his CSEmp selection. I want to get the data once and keep it in memory and filter it and display it. I just don't see what I'm doing wrong. Nulls are allowed but the filter can't deal with them.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room trying to forget the past
    Posts
    4,087

    Re: Grid doesn't exception with a lot of rows, then I filter and it exceptions with l

    So all this time, I've been filtering my grids wrong? I decided to take a filter-my-grids 101 class and I copied this code from a stackoverflow post and I am not exceptioning anymore.

    Code:
            private void PopulateCombined(string csEmp)
            {
                string sFilter = String.Format("CSEmp = '{0}'", lkupCSEmp.EditValue);
                string sSort = "";
                DataRow[] filteredRows; // = dtCombined.Select(sFilter, sSort);
                filteredRows = dtCombined.Select(sFilter);
                DataTable dt2 = dtCombined.Clone();
                foreach (DataRow d in filteredRows)
                    dt2.ImportRow(d);
                gcCombined.DataSource = dt2;
            }
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,261

    Re: Grid doesn't exception with a lot of rows, then I filter and it exceptions with l

    Personally I'd have gone with a BindingSource... and filtered that... After all, that's what it's for (partly at least).

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    33,728

    Re: Grid doesn't exception with a lot of rows, then I filter and it exceptions with l

    Alternatively, you could use the DataView, which has a RowFilter property that uses the same syntax as .Select, and can be bound directly, rather than creating arrays of datarows.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room trying to forget the past
    Posts
    4,087

    Re: Grid doesn't exception with a lot of rows, then I filter and it exceptions with l

    I wasn't really looking for an alternative, more an explanation of what was wrong with the method I was using.
    It would be one thing if I posted, how do I do this. I posted, this is how I am doing this and what is wrong with it.
    I found a solution (post #2); I just didn't understand what was wrong with post #1.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width