Scrolling problems in datagrid with invisible columns

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Igor Mendizabal

    Scrolling problems in datagrid with invisible columns

    Hello,

    We're doing our own datagrid based on the System.windows. forms.datagrid
    control, and are having some problems with horizontal scrolling.

    In general, we construct our datagrid adding a tablestyle and
    gridcolumnstyle s to that tablestyle. If we have invisible columns, we add
    the gridcolumnstyle with Width = 0 (couldn't find any other way to do it,
    because there is no Visible property available...).

    When we change column with the TAB key, it doesn't work right if the
    invisible columns are in the visible area of the grid. Looking at the code
    of the EnsureVisible method of the datagrid, it's something like this:
    -----------------------------------------------------------
    private void EnsureVisible(i nt row, int col) {
    int local0;
    if (row < this.firstVisib leRow || row >= this.firstVisib leRow +
    this.numTotally VisibleRows) {
    local0 = this.ComputeDel taRows(row);
    this.ScrollDown (local0);
    }
    if (this.firstVisi bleCol != 0 || this.numVisible Cols != 0 ||
    this.lastTotall yVisibleCol != -1)
    goto i-1;
    return;
    do {
    this.ScrollToCo lumn(col);
    } while (col < this.firstVisib leCol || col == this.firstVisib leCol &&
    this.negOffset != 0 || this.lastTotall yVisibleCol == -1 && col >
    this.firstVisib leCol || this.lastTotall yVisibleCol > -1 && col >
    this.lastTotall yVisibleCol);
    }
    -----------------------------------------------------------
    The problem is that, even if we can't see, for example, the column 0 because
    it has its Width=0, the datagrid keeps saying that FirtsVisibleCol =0, so it
    doesn't scroll right when it should. I guess the same is happening with the
    rest of the private properties (numVisibleCols and lastTotallyVisi bleCol)

    Anybody has any ideas of how we can solve this problem? Is there a way to
    tell the datagrid that Column0 is actually invisible?

    Right now, the only way I can think of doing it is controlling columns with
    Width=0 and scrolling the grid "by hand"...

    Thank You very much,

    Igor Mendizabal


  • Cor Ligthert [MVP]

    #2
    Re: Scrolling problems in datagrid with invisible columns

    Igor,

    Not using a column in a datagrid with styles means not creating a column for
    it, what is your problem with that?

    And when you don't use a style than you can hide it.

    See this sample on our site, there are more samples about styles on our
    site.



    (Using columns in a datagrid has always to do with mappings.)

    I hope this helps,

    Cor



    Comment

    • Igor Mendizabal

      #3
      Re: Scrolling problems in datagrid with invisible columns

      Hello Cor,

      I thought about your suggestion, but doesn't work in our case. The problem
      is that our grids are mostly configurable by the user (they can
      enable/reorder/hide columns), and there is a lot of code written by now that
      accesses those columns, even if they are hidden, because it supposes that
      they are there, only that we can't see them.

      Anyway, I tried not to add the invisible gridcolumnstyle s, and even thogh
      the scrolling works fine, I broke more things than I fixed with that change,
      so I'm gonna try to control if it should scroll in the CurrentCellChan ged
      event, and use the GridHScrolled method to make it scroll.

      Thank you very much anyway,

      Igor

      "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> escribió en el mensaje
      news:O7fbXcigFH A.1416@TK2MSFTN GP09.phx.gbl...[color=blue]
      > Igor,
      >
      > Not using a column in a datagrid with styles means not creating a column[/color]
      for[color=blue]
      > it, what is your problem with that?
      >
      > And when you don't use a style than you can hide it.
      >
      > See this sample on our site, there are more samples about styles on our
      > site.
      >
      >[/color]
      http://www.windowsformsdatagridhelp....3-a3539697edbd[color=blue]
      >
      > (Using columns in a datagrid has always to do with mappings.)
      >
      > I hope this helps,
      >
      > Cor
      >
      >
      >[/color]


      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Scrolling problems in datagrid with invisible columns

        Igor,

        AFAIK is setting the mapping of a column to nothing enough to do what you
        want when you use tablestyles.

        Cor


        Comment

        Working...