Click here to Skip to main content
15,891,529 members
Home / Discussions / Windows Forms
   

Windows Forms

 
GeneralRe: Changing form controlls at runtime Pin
Gilliann27-Aug-09 16:41
Gilliann27-Aug-09 16:41 
GeneralRe: Changing form controlls at runtime Pin
Mycroft Holmes27-Aug-09 16:53
professionalMycroft Holmes27-Aug-09 16:53 
AnswerRe: Changing form controlls at runtime Pin
darkelv27-Aug-09 17:08
darkelv27-Aug-09 17:08 
GeneralRe: Changing form controlls at runtime Pin
Luc Pattyn28-Aug-09 0:57
sitebuilderLuc Pattyn28-Aug-09 0:57 
JokeRe: Changing form controlls at runtime Pin
Mycroft Holmes29-Aug-09 18:29
professionalMycroft Holmes29-Aug-09 18:29 
GeneralRe: Changing form controlls at runtime Pin
BillWoodruff1-Sep-09 14:47
professionalBillWoodruff1-Sep-09 14:47 
GeneralRe: Changing form controlls at runtime Pin
darkelv3-Sep-09 19:36
darkelv3-Sep-09 19:36 
GeneralDatagridview formatting [modified] Pin
Mycroft Holmes25-Aug-09 17:59
professionalMycroft Holmes25-Aug-09 17:59 
This is a rant not a question.

I have 2 DGVs with approx 1000 rows each on a single form, each has 14 columns and I need to format the alignment and text of the last 6 columns.

I created this utility event that uses the cell format event to set the alignment based on the columns underlying data type (ValueType) and assigned it to both grids. Performance is not good, there is an appreciable delay when loading and filtering the grids, about 3-5 seconds
public static void dgCellFormat(object sender, DataGridViewCellFormattingEventArgs e)
{
    DataGridViewColumn oCol = (sender as DataGridView).Columns[e.ColumnIndex];
    string vt = oCol.ValueType.ToString().ToLower();
    switch (vt)
    {
        case "system.int32":
        case "system.int16":
        case "system.int64":
            e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            //if the right 2 characters are not ID then add , to the value
            if (!oCol.HeaderText.EndsWith("ID"))
            {
                e.CellStyle.Format = "#,#";
            }
            break;
        case "system.decimal":
            e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            //if the right 2 characters are not ID then add , to the value
            if (!oCol.HeaderText.EndsWith("ID"))
            {
                e.CellStyle.Format = "#,#.00";
            }
            break;
        case "system.datetime":
            e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            break;
    }
}


So I thought if cell formatting is slow then formatting the columns defaultcellstyle should be better performance. WRONG Mad | :mad: , setting the defaultcellstyle instead of cellformatting resulted in a delay of approx 50 seconds when loading. I suppose b/c the grid formats all the data instead of just the data on display.


[edit] Thanks to comments from darklev I moved the above formatting into the column creation process, removing the AutoGenerate columns and formatting the columns to meet my requirements. Work perfectly without the overhead. [/edit]


Last modified: 123hrs 51mins after originally posted --



GeneralRe: Datagridview formatting Pin
Obsidian71329-Aug-09 16:08
Obsidian71329-Aug-09 16:08 
GeneralRe: Datagridview formatting Pin
Mycroft Holmes29-Aug-09 18:26
professionalMycroft Holmes29-Aug-09 18:26 
GeneralRe: Datagridview formatting Pin
darkelv29-Aug-09 18:59
darkelv29-Aug-09 18:59 
GeneralRe: Datagridview formatting Pin
Mycroft Holmes29-Aug-09 21:00
professionalMycroft Holmes29-Aug-09 21:00 
GeneralRe: Datagridview formatting Pin
darkelv29-Aug-09 23:18
darkelv29-Aug-09 23:18 
GeneralRe: Datagridview formatting Pin
Mycroft Holmes29-Aug-09 23:32
professionalMycroft Holmes29-Aug-09 23:32 
QuestionRegions in code Pin
εїзεїзεїз24-Aug-09 22:27
εїзεїзεїз24-Aug-09 22:27 
AnswerRe: Regions in code Pin
Henry Minute25-Aug-09 1:08
Henry Minute25-Aug-09 1:08 
GeneralRe: Regions in code Pin
εїзεїзεїз25-Aug-09 5:49
εїзεїзεїз25-Aug-09 5:49 
GeneralRe: Regions in code Pin
Henry Minute25-Aug-09 5:55
Henry Minute25-Aug-09 5:55 
GeneralRe: Regions in code Pin
εїзεїзεїз25-Aug-09 14:58
εїзεїзεїз25-Aug-09 14:58 
GeneralRe: Regions in code Pin
εїзεїзεїз29-Aug-09 22:12
εїзεїзεїз29-Aug-09 22:12 
QuestionDisabling scrolling in RichTextBox ?? Pin
ashkan87_224-Aug-09 0:12
ashkan87_224-Aug-09 0:12 
AnswerRe: Disabling scrolling in RichTextBox ?? Pin
εїзεїзεїз24-Aug-09 15:19
εїзεїзεїз24-Aug-09 15:19 
GeneralRe: Disabling scrolling in RichTextBox ?? Pin
ashkan87_225-Aug-09 0:11
ashkan87_225-Aug-09 0:11 
RantStupid Scrollbar bug Pin
LloydA11123-Aug-09 8:43
LloydA11123-Aug-09 8:43 
GeneralRe: Stupid Scrollbar bug Pin
Alan N23-Aug-09 13:01
Alan N23-Aug-09 13:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.