Hi @vijay kumar , Welcome to Microsoft Q&A.
Since you don't need the calculation part, you just need to add the dataGridView1_CellFormatting event of the datagridview. Convert qualified data as needed. Here I use list to simulate the acquisition of the database.
using System;
using System.Collections.Generic;
using System. Windows. Forms;
namespace_7_19_2
{
public partial class Form1: Form
{
public class customer details
{
public int ID
{
get;
set;
}
public String Name
{
get;
set;
}
public int DR
{
get;
set;
}
public int CR
{
get;
set;
}
public int ClosingBlance
{
get;
set;
}
public customer details(int iD, string name, int dR, int cR, int closingBlance)
{
ID = iD;
Name = name;
DR = dR;
CR = cR;
ClosingBlance = closingBlance;
}
}
public List < customer details > list = new List < customer details > ();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
list.Add(new customerdetails(1, "XY co.", 0, 0, -2000));
list.Add(new customerdetails(2, "XY co.", 3000, 0, 1000));
list.Add(new customerdetails(3, "XY co.", 2000, 0, 3000));
dataGridView1. DataSource = list;
}
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if(dataGridView1. DataSource != null)
{
// Determine whether it is in a specific column (assuming it is column 5), and the data is of type int
if(e.ColumnIndex == 4 && e.Value is int intValue)
{
// Display int data with "-" as string ending with " CR"
if(intValue < 0)
{
e.Value = Math.Abs(intValue).ToString() + " CR";
e.FormattingApplied = true; // Indicates that the display value has been modified
}
else
{
e.Value = intValue.ToString() + "DR";
e.FormattingApplied = true; // Indicates that the display value has been modified
}
}
}
}
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.