Datagrid Organization

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 3928 Views - Last Post: 05 October 2011 - 09:16 AM Rate Topic: -----

#1 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Datagrid Organization

Posted 03 October 2011 - 05:36 AM

May I ask a suggestion about this datagrid. I have this datagrid but it has so many column and I am going to total each and every column. If I am going to put a textbox or label, it'll be kinda difficult because it will not align to the column. Any solution you may suggest?

Another thing is this form for Daily Income.
I want the form at the back (Main Form) not clickable unless I closes the Daily Income Form. So that the Daily Income Form will not go at the back of the Main Form. It is like you were saving a file on a text editor that you can't click the window behind it. That's what I meant.

Posted Image

Is This A Good Question/Topic? 0
  • +

Replies To: Datagrid Organization

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Datagrid Organization

Posted 03 October 2011 - 06:24 AM

The first question: So you are finding the way to display those data or sum them? You can sum them from database if this is what you need.

Second: Use ShowDialog() instead of Show()
Was This Post Helpful? 0
  • +
  • -

#3 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Re: Datagrid Organization

Posted 03 October 2011 - 02:54 PM

View Postsmohd, on 03 October 2011 - 07:24 AM, said:

The first question: So you are finding the way to display those data or sum them? You can sum them from database if this is what you need.

Second: Use ShowDialog() instead of Show()


First : Is it possible to sum them all the way while entering the other data? If I am going to sum them from database, I possibly need to save them first. Isn't it?

Thank you bro the second one works :)

This post has been edited by k3nnt0ter0: 03 October 2011 - 02:59 PM

Was This Post Helpful? 0
  • +
  • -

#4 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Datagrid Organization

Posted 03 October 2011 - 08:09 PM

Yes, you can loop in all cells of your data grid view and sum the values
Was This Post Helpful? 0
  • +
  • -

#5 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Re: Datagrid Organization

Posted 03 October 2011 - 09:17 PM

View Postsmohd, on 03 October 2011 - 09:09 PM, said:

Yes, you can loop in all cells of your data grid view and sum the values


If that is possible, how am I going to insert the sum aligned to the column? Is there any solution?
Or suggestion that you could recommend to solve my problem? I just want it not hard to view the sum.

This post has been edited by k3nnt0ter0: 03 October 2011 - 09:18 PM

Was This Post Helpful? 0
  • +
  • -

#6 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Datagrid Organization

Posted 03 October 2011 - 09:24 PM

So you mean every column will have its own sum? Yes, I have two suggestions:
- Use the last row to compute the sum of every column, this can be impossible if you need to add more things in grid view

- Put another grid view down the first one, with the same alignment of columns, set its show header property to false(so it hides the column names) and will have one row to add the summations..
Was This Post Helpful? 1
  • +
  • -

#7 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Re: Datagrid Organization

Posted 03 October 2011 - 10:20 PM

View Postsmohd, on 03 October 2011 - 10:24 PM, said:

So you mean every column will have its own sum? Yes, I have two suggestions:
- Use the last row to compute the sum of every column, this can be impossible if you need to add more things in grid view

- Put another grid view down the first one, with the same alignment of columns, set its show header property to false(so it hides the column names) and will have one row to add the summations..


On your second suggestion, will it follow the upper datagrid? I mean when you scroll the upper datagrid, will the lower scroll also?
Was This Post Helpful? 0
  • +
  • -

#8 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Datagrid Organization

Posted 03 October 2011 - 10:55 PM

No, the second one do not need to scroll, it will have only one row with no headings just to display the summation
Was This Post Helpful? 0
  • +
  • -

#9 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Re: Datagrid Organization

Posted 05 October 2011 - 01:20 AM

View Postsmohd, on 03 October 2011 - 11:55 PM, said:

No, the second one do not need to scroll, it will have only one row with no headings just to display the summation


If it doesn't have scroll, how do I determine if what total is in the column?
The upper datagrid has its scroll and it can move left or right.
Was This Post Helpful? 0
  • +
  • -

#10 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Datagrid Organization

Posted 05 October 2011 - 01:45 AM

Oh, if the horizontal scroll it will be problem. Sorry I thought it is vertical scroll.

Ok lets think of another way to display the data! Doh! I think the way I have now is only to display sum of every column at the last cell of the column.
Was This Post Helpful? 0
  • +
  • -

#11 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Re: Datagrid Organization

Posted 05 October 2011 - 03:49 AM

View Postsmohd, on 05 October 2011 - 02:45 AM, said:

Oh, if the horizontal scroll it will be problem. Sorry I thought it is vertical scroll.

Ok lets think of another way to display the data! Doh! I think the way I have now is only to display sum of every column at the last cell of the column.


May I have an Example of it? Actually this is my very first time using a data grid. I don't even know how to add each column.
Was This Post Helpful? 0
  • +
  • -

#12 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Datagrid Organization

Posted 05 October 2011 - 04:09 AM

If you want to add the column, just loop through it and add the value of each cell in that column. Something like:
Dim sum As Double = 0.0
For i As Integer = 0 To DataGridView1.RowCount - 2
   sum += Double.Parse(DataGridView1.Rows(i).Cells(0).Value) 'this will count the first column(0)
Next

Was This Post Helpful? 0
  • +
  • -

#13 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: Datagrid Organization

Posted 05 October 2011 - 07:01 AM

I come from a web-programming background so I'm just curious as to why you wouldn't consider handling the DataGridView's Scroll Event in one of the DataGridViews and control the other DataGridView using the data you get in this event?

If I were to do this I would hide the scroll bars in the main DataGridView while showing them in the "summary" DataGridView...and I would handle the "summary" DataGridView's Scroll event so that I could synchronize the scrolling on both DataGridViews.

-Frinny
Was This Post Helpful? 0
  • +
  • -

#14 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Re: Datagrid Organization

Posted 05 October 2011 - 07:39 AM

View PostFrinavale, on 05 October 2011 - 08:01 AM, said:

I come from a web-programming background so I'm just curious as to why you wouldn't consider handling the DataGridView's Scroll Event in one of the DataGridViews and control the other DataGridView using the data you get in this event?

If I were to do this I would hide the scroll bars in the main DataGridView while showing them in the "summary" DataGridView...and I would handle the "summary" DataGridView's Scroll event so that I could synchronize the scrolling on both DataGridViews.

-Frinny

What do you mean by hiding the scroll bars in the main datagrid? Correct me if I misunderstood it. If I were to hide the scroll in the main datagrid, how am I suppose to enter data on the other fields? I have here many fields. Kindly elaborate if you don't mind. I am new with this datagrid thing.
Was This Post Helpful? 0
  • +
  • -

#15 demausdauth  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 181
  • View blog
  • Posts: 659
  • Joined: 03-February 10

Re: Datagrid Organization

Posted 05 October 2011 - 08:09 AM

Another option is to put the total in the Column header. Not sure if that would fit with what you want to do.


    Private Sub DataGridHeaderTotals(ByVal passDataGrid As DataGridView, ByVal columnIndex As Integer)

        'total for column
        Dim columnTotal As Double
        Dim counterAdjust As Integer = 1
        If passDataGrid.AllowUserToAddRows Then counterAdjust = 2

        ''loop through columns
        For loopIndex As Integer = 0 To passDataGrid.RowCount - counterAdjust

            Dim columnValue As Double

            'check to see if the value in the column can be cast to valid double
            ' will cause the total to skip null values, alphanumerical strings
            If Double.TryParse(passDataGrid(columnIndex, loopIndex).Value.ToString(), columnValue) Then
                columnTotal += columnValue
            End If
        Next

        'set the header text of the column to the column name and the column total with formatting (in this case for 2 decimal places)
        passDataGrid.Columns(columnIndex).HeaderText = String.Format("{0}({1:0.00})", passDataGrid.Columns(columnIndex).HeaderText, columnTotal)

    End Sub



And this is only basic code, could easily be made better.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2