How do I format Column when a Gridview loads?
-
How do I format Column when a Gridview loads? Details: I have a grid named : SubcategoryGrid the grid is binded to a data binding source. there is a column in that grid(double type), I need to apply a simple conversion formula after the data binding completes what gridview argument do I use? or how would I go on about this?
-
How do I format Column when a Gridview loads? Details: I have a grid named : SubcategoryGrid the grid is binded to a data binding source. there is a column in that grid(double type), I need to apply a simple conversion formula after the data binding completes what gridview argument do I use? or how would I go on about this?
Hi, have a look at the CellFormatting event. You could watch the value (e.Value) to be displayed and: 1. modify it, 2. or apply a special formatting (dgv.Columns[COL].DefaultCellStyle.Format="#,###";), 3. or set a special backcolor (e.CellStyle.BackColor=Color.Yellow; however this does not work for empty cells!). I have used some of the above in my CP Vanity[^] article. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Hi, have a look at the CellFormatting event. You could watch the value (e.Value) to be displayed and: 1. modify it, 2. or apply a special formatting (dgv.Columns[COL].DefaultCellStyle.Format="#,###";), 3. or set a special backcolor (e.CellStyle.BackColor=Color.Yellow; however this does not work for empty cells!). I have used some of the above in my CP Vanity[^] article. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Thanks, this is what I have: Class:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
}What args do I use in designer?? I tried this event to trigger cellformating: this.SubcategoryGrid.DataBindings += ........
-
How do I format Column when a Gridview loads? Details: I have a grid named : SubcategoryGrid the grid is binded to a data binding source. there is a column in that grid(double type), I need to apply a simple conversion formula after the data binding completes what gridview argument do I use? or how would I go on about this?
-
Thanks, this is what I have: Class:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
}What args do I use in designer?? I tried this event to trigger cellformating: this.SubcategoryGrid.DataBindings += ........
:confused: :confused: :confused: AFAIK there are two distinct mechanisms, one to provide the data (databinding), one to display the data (formatting). The binding is whatever you want it to be. The formatting will fire the CellFormatting event if you wire it up, which you can do by double-clicking the event in the events list, or by adding a
dataGridView1.CellFormatting+=dataGridView1_CellFormatting;
statement in the form's constructor. As you already have the outline, you probably have done the former already. Now start manipulating the current cell inside your event handler, any way you want (You did not specify what kind of "simple conversion formula" you want). :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Why does it have to happen after the binding? Is there some reason you can't use DataFormatString[^]?
That is for a WebUI thingy, isn't it? I believe the OP wants a WinForm with a DataGridView. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
:confused: :confused: :confused: AFAIK there are two distinct mechanisms, one to provide the data (databinding), one to display the data (formatting). The binding is whatever you want it to be. The formatting will fire the CellFormatting event if you wire it up, which you can do by double-clicking the event in the events list, or by adding a
dataGridView1.CellFormatting+=dataGridView1_CellFormatting;
statement in the form's constructor. As you already have the outline, you probably have done the former already. Now start manipulating the current cell inside your event handler, any way you want (You did not specify what kind of "simple conversion formula" you want). :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
That is for a WebUI thingy, isn't it? I believe the OP wants a WinForm with a DataGridView. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Ahh he used the wrong control name. DataGridView and GridView are two completely different things. Using the correct term can vastly increase chances of finding useful info. A simple MSDN search of DataGridView gives the DataGridView page[^] which contains a list of common tasks with number 6 being How to: Customize Data Formatting in the Windows Forms DataGridView Control[^]
-
Ahh he used the wrong control name. DataGridView and GridView are two completely different things. Using the correct term can vastly increase chances of finding useful info. A simple MSDN search of DataGridView gives the DataGridView page[^] which contains a list of common tasks with number 6 being How to: Customize Data Formatting in the Windows Forms DataGridView Control[^]
T M Gray wrote:
Ahh he used the wrong control name
Happens all the time, we all get used to it. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.