Click here to Skip to main content
14,209,923 members
Rate this:
Please Sign up or sign in to vote.
See more:
Dear all 

i have 7 tables of COA  as show in the picture attached. what i need is whenever opening balance goto - (negative) , the type must automatically show CR sign and whenever that account goto positive + , it must change to DR automatically 

What I have tried:

i tried nothing yet becz i do not have idea how i can do it . please provide me some good help to solve my issue,.
Updated 11-Jun-19 20:26pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You can do this using DataGridView events, see CodeProject article: DataGridView Event Sequences[^]
Here is an example using CellValidating() Walkthrough: Validating Data in the Windows Forms DataGridView Control | Microsoft Docs[^]

To get you started:
private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)
    var cell = this.dataGridView1[e.ColumnIndex, e.RowIndex];
    float n;

    if (float.TryParse(cell.Value.ToString(), out n))
        if (n < 0)
            cell.Value += " CR";
            cell.Value += " DB";
Member 12654313 12-Jun-19 4:13am
thank you for your code i was looking for code . i change your code to .net
Dim cell = Me.COADataGridView(e.ColumnIndex, e.RowIndex)
Dim n As Single

If Single.TryParse(cell.Value.ToString(), n) Then

If n < 0 Then
cell.Value += " CR"
cell.Value += " DB"
End If
End If

your code worked ok but i have a separate column name type , under that column i need , whenever balance goes to -tive, the sign of DR in type column change to CR for that particular account , also i need that code to work on form load event . i need it to run while user open chart of accounts
RickZeeland 12-Jun-19 6:24am
So far I could not find a suitable event on form load, tried RowsAdded() and CellPainting(). So you will have to do that in a for loop I'm afraid. You can test for the correct column number with e.ColumnIndex.
Member 12654313 12-Jun-19 7:17am
suppose my column of TYPE is 7 and OPENING BALANCE is 6 so how can i do it with your code ?
RickZeeland 12-Jun-19 7:28am
If e.ColumnIndex = 6 And Single.TryParse(cell.Value.ToString(), n) Then
Member 12654313 12-Jun-19 7:47am
not working :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190617.3 | Last Updated 12 Jun 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100