Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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,.
Posted
Updated 11-Jun-19 20:26pm

1 solution

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";
        }
        else
        {
            cell.Value += " DB";
        }
    }
}
 
Share this answer
 
v2
Comments
Member 12654313 12-Jun-19 4:13am    
thank you for your code i was looking for vb.net 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"
Else
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900