Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
210
Dynamic columns in a fixed width UltraGrid
posted

Hi,

  I have an UltraGrid that has a fixed width (total width of grid is fixed) with no horizontal scroll bar. At runtime I am dynamically creating columns and adding them to the grid. The columns width themselves are based on the size of the data in them. The number of columns that I need to create will vary at runtime, there could be 3 or there could be 20.  Because of the fixed width of the grid I will not always be able to see all the columns in it. At the moment I just add all the columns and usually only a subset of them are visible in the grid. However, sometimes the last visible column is partly cut off from view (see screenshot).  What I would like to be able to do is detect which is the last fully visible column and not add any more after that.  Is there a way to do this?
John
Parents
  • 48586
    Verified Answer
    posted

    Hello,

    What you could do in your case is to iterate columns' collection and to sum their width, so when this sum is more that the width of UltraGdid, this meant that the last column involved in this sum is part-visible. So you could use code like:

     
     int totalColWidth = 0;
                int colIndex = 0;
                
                while (totalColWidth < ultraGrid1.Width && colIndex != -1)
                {
                    totalColWidth += ultraGrid1.DisplayLayout.Bands[0].Columns[colIndex].Width;
                    colIndex++;
                    if (colIndex >= ultraGrid1.DisplayLayout.Bands[0].Columns.Count)
                        colIndex = -1;
                }
                // column at index colIndex is part visible if colIndex = -1 all columns are full visible 
    

    Please let me know if you have any further questions.

Reply Children
No Data