|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataGridView (.NET 2.0 Control) question about formattingHi,
I have what I think should be a simple question about formatting a column in my datagridview control as currency. I used Visual Studio 2005 to add a column to my DataGridView control named "Price". I set the DefaultCellStyle.Format value to "C2" indicating that I want the format of this cell to be currency with 2 decimal places. However, when I enter a number in the column it stays as I enter it. For example, if I entre a "1" it stays "1" rather than being formatted as "$1.00" Doesn anyone know if I'm missing something? I've read lots of documentation at the MSDN2 site but I can't find anything to help me. I've started to work on custom formatting but it's seems to me that the control was designed to allow for automatic formatting. Thanks in Advance! Try using only "C". By default, currency values should only have 2 decimal
places. -- Show quoteChristopher A. Reed "The oxen are slow, but the earth is patient." " g" <j> wrote in message news:9sadnbfNNosBbCzeRVn-uQ@comcast.com... > Hi, > > I have what I think should be a simple question about formatting a column > in my datagridview control as currency. > > I used Visual Studio 2005 to add a column to my DataGridView control named > "Price". I set the DefaultCellStyle.Format value to "C2" indicating that > I want the format of this cell to be currency with 2 decimal places. > However, when I enter a number in the column it stays as I enter it. For > example, if I entre a "1" it stays "1" rather than being formatted as > "$1.00" > > Doesn anyone know if I'm missing something? I've read lots of > documentation at the MSDN2 site but I can't find anything to help me. > I've started to work on custom formatting but it's seems to me that the > control was designed to allow for automatic formatting. > > Thanks in Advance! > Hi Christopher,
Thanks for your response. That doesn't do the trick however. I added a form to allow the user to add data to the DataGridView rather than editing it directly. When i did this the correct columns were formatted as currency. This was because I added the data using the Rows.Add() method which can handle decimal types directly. Apparently, it's only formatted as currency when it sees a number type and entering data directly into the control doesn't qualify. Show quote "Christopher Reed" <carttu@nospam.nospam> wrote in message news:uX6MWq1CGHA.1180@TK2MSFTNGP09.phx.gbl... > Try using only "C". By default, currency values should only have 2 > decimal places. > -- > Christopher A. Reed > "The oxen are slow, but the earth is patient." > > " g" <j> wrote in message news:9sadnbfNNosBbCzeRVn-uQ@comcast.com... >> Hi, >> >> I have what I think should be a simple question about formatting a column >> in my datagridview control as currency. >> >> I used Visual Studio 2005 to add a column to my DataGridView control >> named "Price". I set the DefaultCellStyle.Format value to "C2" >> indicating that I want the format of this cell to be currency with 2 >> decimal places. However, when I enter a number in the column it stays as >> I enter it. For example, if I entre a "1" it stays "1" rather than being >> formatted as "$1.00" >> >> Doesn anyone know if I'm missing something? I've read lots of >> documentation at the MSDN2 site but I can't find anything to help me. >> I've started to work on custom formatting but it's seems to me that the >> control was designed to allow for automatic formatting. >> >> Thanks in Advance! >> > > You're right. The format is for displaying the value, not while editing the
value. -- Show quoteChristopher A. Reed "The oxen are slow, but the earth is patient." " g" <j> wrote in message news:0NKdnf0sndCssy_eRVn-sg@comcast.com... > Hi Christopher, > > Thanks for your response. That doesn't do the trick however. > > I added a form to allow the user to add data to the DataGridView rather > than editing it directly. When i did this the correct columns were > formatted as currency. This was because I added the data using the > Rows.Add() method which can handle decimal types directly. Apparently, > it's only formatted as currency when it sees a number type and entering > data directly into the control doesn't qualify. > "Christopher Reed" <carttu@nospam.nospam> wrote in message > news:uX6MWq1CGHA.1180@TK2MSFTNGP09.phx.gbl... >> Try using only "C". By default, currency values should only have 2 >> decimal places. >> -- >> Christopher A. Reed >> "The oxen are slow, but the earth is patient." >> >> " g" <j> wrote in message news:9sadnbfNNosBbCzeRVn-uQ@comcast.com... >>> Hi, >>> >>> I have what I think should be a simple question about formatting a >>> column in my datagridview control as currency. >>> >>> I used Visual Studio 2005 to add a column to my DataGridView control >>> named "Price". I set the DefaultCellStyle.Format value to "C2" >>> indicating that I want the format of this cell to be currency with 2 >>> decimal places. However, when I enter a number in the column it stays as >>> I enter it. For example, if I entre a "1" it stays "1" rather than >>> being formatted as "$1.00" >>> >>> Doesn anyone know if I'm missing something? I've read lots of >>> documentation at the MSDN2 site but I can't find anything to help me. >>> I've started to work on custom formatting but it's seems to me that the >>> control was designed to allow for automatic formatting. >>> >>> Thanks in Advance! >>> >> >> > > Hi,
"g" wrote: You could subscribe to the ColumnChanging event of the DataTable and set the > Hi Christopher, > > Thanks for your response. That doesn't do the trick however. > > I added a form to allow the user to add data to the DataGridView rather than > editing it directly. When i did this the correct columns were formatted as > currency. This was because I added the data using the Rows.Add() method > which can handle decimal types directly. Apparently, it's only formatted as > currency when it sees a number type and entering data directly into the > control doesn't qualify. ProposedValue in the DataColumnChangeEventArgs. I don't know if this is the best way, but I think it can solve your problem. Kind regards, -- Tom Tempelaere. |
|||||||||||||||||||||||