If the Balance of Party column ($ClosingBalance) is numeric, then try adding this line:
dataGridView1.Columns[1].DefaultCellStyle.Format = "-0.00;+0.00;0";
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a DataGridview which is showing two columns column a and column b. columns b is showing balance of parties in + and - and 0. I want to programmatically reverse the signs of each balance in every cell in the column b. how to achieve that please suggest. I am using the below code to query data.
using (OdbcConnection con = new OdbcConnection(source))
{
string query = "Select $Name, $ClosingBalance from Ledger where $$IsDr:$ClosingBalance order by $ClosingBalance DESC";
using (OdbcDataAdapter dadapter = new OdbcDataAdapter(query, con))
{
DataTable table = new DataTable();
dadapter.Fill(table);
this. dataGridView1.DataSource = table.
dataGridView1.Columns[0].HeaderText = "Name of Party";
dataGridView1.Columns[1].HeaderText = "Balance of Party";
dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
clearGrid(dataGridView1);
}
}
}
}
}
// code for removing null values only
private void clearGrid(DataGridView view)
{
for (int i = 1; i < view.RowCount - 1; i++)
{
if (view.Rows[i].Cells[0].Value.ToString() == "" || view.Rows[i].Cells[1].Value.ToString() == "")
{
view.Rows.RemoveAt(i);
i--;
}
}
}
If the Balance of Party column ($ClosingBalance) is numeric, then try adding this line:
dataGridView1.Columns[1].DefaultCellStyle.Format = "-0.00;+0.00;0";