Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1077419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:34:22+00:00 2026-05-16T21:34:22+00:00

How do you find number of items in a column inside a grid? I

  • 0

How do you find number of items in a column inside a grid?

I have a grid (listview control to be specific), and have some items.
Some times a given row might not be full. ANd can have values in fewer than maximum columns. I need to find Number of items in a given Column.

If the grid is like

1   2   3
4   5   6
7       

and if input column is 1, then we need to output 3, and 2 for input of 2 or 3.

I have variables to for ItemCount, CoulmnCount and RowCount which track number of items, rows and columns.

A very rudimentar way would be something like this:

int iItemCount=0,iItemInColumn=0;
for(int iCol=0;iCol<iColumnCount;iCol++)
    for(int iRow=0;iRow<iRowCount;iRow++,iItemCount++)
        if(iCol==iInputCol && iItemCount<iTotalItems)
            iItemInColumn++;

Can you guys think of any sophesticated way, which does not need loops? possible utilizing just 3 variables which I already have for tracking?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:34:22+00:00Added an answer on May 16, 2026 at 9:34 pm

    Assuming 0-based indexes:

    def itemsInColumn(itemCount, columnCount, inputColumn):
      lastItemColumn = (itemCount - 1) % columnCount
      if inputColumn <= lastItemColumn:
        return (itemCount + columnCount - 1) / columnCount
      else:
        return itemCount / columnCount
    

    It depends on the total number of items (itemCount) and the number of columns (columnCount). It just computes itemCount / columnCount, and rounds up or down depending on whether the input column is less than or equal to the last item’s column.

    The computation “(itemCount + columnCount – 1) / columnCount” is just a trick for rounding up using integer division. In general, given positive integers a and b: ceil(a / b) = (a + b – 1) div b, where div is integer division.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find number of unique characters in a String. Solution have
Does anybody know how to find the number of rows affected AFTER I have
I want to find items in common from the following_list column in a table
My Listview control contains 4 columns and 30 rows. I can retrieve the row
I'm trying to link the items from a specific column, but each one will
I'm trying to find out the index number of the last list item but
How do I find the number of keys in a hash, like using $#
I want to find the number of the week which a day belongs to
How do you find the number of days in a month in Java?
How do I find the number in line number may not be in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.