Reputation: 2394
I have datagridview
control with a column formatted to have currency values. The data was NOT bound to the datagridview
using data binding, it was simply assigned to each column. i have added a cellDoubleClick
event to send value in cells to textboxes. But when currency values were sent to textboxes they removed formatting and it happened automatically ie. the $ sign and grouping of digits gets removed. Why this happens? and how do i make it not do it?
Here is some screen shots
all loaded data with formatting to the datagridview control
double click on a cell send data to textboxes
Here is the code that sends data to textboxes
private void dgvRooms_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
try
{
cmbBlockCode.Text = dgvRooms[1, e.RowIndex].Value.ToString().Trim();
cmbLevels.Text = dgvRooms[2, e.RowIndex].Value.ToString().Trim();
tbxRoomNo.Text = dgvRooms[0, e.RowIndex].Value.ToString().Trim();
tbxAval.Text = dgvRooms[3, e.RowIndex].Value.ToString().Trim();
tbxRentWeek.Text = dgvRooms[4, e.RowIndex].Value.ToString().Trim(); //String.Format("{0:C2}", );
tbxBondAmount.Text = dgvRooms[5, e.RowIndex].Value.ToString().Trim();
}
catch (Exception)
{
throw;
}
}
Upvotes: 0
Views: 1095
Reputation: 54453
..the $ sign and grouping of digits get removed. Why does this happen? And how do I make it not do it?
The Value
is the value and you should be glad for this : With all the formatting in it, how could you still use it in a calculation.. etc?
To get it with the formatting you can copy its FormattedValue
like this:.
tbxRentWeek.Text = dgvRooms[4, e.RowIndex].FormattedValue.ToString().Trim();
Upvotes: 3