Click here to Skip to main content
15,887,596 members
Home / Discussions / C#
   

C#

 
AnswerRe: thread abort exception when service ends to where it has been invoked from Pin
Guffa27-Oct-08 15:48
Guffa27-Oct-08 15:48 
GeneralRe: thread abort exception when service ends to where it has been invoked from Pin
stephan_00727-Oct-08 23:29
stephan_00727-Oct-08 23:29 
QuestionSplitting up a list of things. Pin
Buckleyindahouse27-Oct-08 11:08
Buckleyindahouse27-Oct-08 11:08 
AnswerRe: Splitting up a list of things. Pin
Guffa27-Oct-08 11:19
Guffa27-Oct-08 11:19 
QuestionFormat The XML with Csharp Pin
zjaffary27-Oct-08 10:35
zjaffary27-Oct-08 10:35 
AnswerCross post and Repost Pin
led mike27-Oct-08 11:03
led mike27-Oct-08 11:03 
GeneralRe: Cross post and Repost Pin
Paul Conrad27-Oct-08 12:30
professionalPaul Conrad27-Oct-08 12:30 
QuestionSpeeding up DataGridView RowCount assignment Pin
AndrusM27-Oct-08 10:10
AndrusM27-Oct-08 10:10 
In code below Line
m_Grid.RowCount = 1000000;

takes 8 seconds.

How to speed it up ?

Andrus.

using System;
using System.Windows.Forms;
using System.Collections.Generic;

class test
{
    [STAThreadAttribute()]
    public static void Main()
    {
        Application.Run(new VirtualModeForm());
    }
}

class VirtualModeForm : Form
{
    private List<DataObject> m_Data = new List<DataObject>();
    private List<bool> m_Visited = new List<bool>();
    DataGridView m_Grid = new DataGridView();
    public VirtualModeForm()
    {
        Controls.Add(m_Grid);
        m_Grid.CellValueNeeded += OnCellValueNeeded;
        InitData();
        InitGrid();
    }

    private void InitData()
    {
        for (int i = 0; i < 1000001 + 1; i++)
        {
            m_Visited.Add(false);
            DataObject obj = new DataObject();
            obj.Id = i;
            obj.Val = 2 * i;
            m_Data.Add(obj);
        }
    }

    private void InitGrid()
    {
        m_Grid.Dock = DockStyle.Fill;
        m_Grid.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCellsExceptHeader);
        m_Grid.VirtualMode = true;
        m_Grid.ReadOnly = true;
        m_Grid.ColumnCount = 108;
        // this line causes 8 seconds delay. how to fix.
        m_Grid.RowCount = 1000000;
    }

    private void OnCellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
    {

        m_Visited[e.RowIndex] = true;
        if (e.ColumnIndex == 0)
        {
            e.Value = m_Data[e.RowIndex].Id;
        }
        else if (e.ColumnIndex == 1)
        {
            e.Value = m_Data[e.RowIndex].Val;
        }
        else if (e.ColumnIndex == 2)
        {

            Random rand = new Random();
            e.Value = rand.Next();
        }
    }
}

public class DataObject
{
    private int m_Id;
    private int m_Val;

    public int Val
    {
        get { return m_Val; }
        set { m_Val = value; }
    }

    public int Id
    {
        get { return m_Id; }
        set { m_Id = value; }
    }

    public int Id1 { get; set; }
    public int Id2 { get; set; }
    public int Id3 { get; set; }
    public int Id4 { get; set; }
    public int Id5 { get; set; }
    public int Id6 { get; set; }
    public int Id7 { get; set; }
    public int Id8 { get; set; }
    public int Id9 { get; set; }
    public int Id10 { get; set; }
    public int Id11 { get; set; }
    public int Id12 { get; set; }
    public int Id13 { get; set; }
    public int Id14 { get; set; }
    public int Id15 { get; set; }
    public int Id16 { get; set; }
    public int Id17 { get; set; }
    public int Id18 { get; set; }
    public int Id19 { get; set; }
    public int Id20 { get; set; }
    public int Id21 { get; set; }
    public int Id22 { get; set; }
    public int Id23 { get; set; }
    public int Id24 { get; set; }
    public int Id25 { get; set; }
    public int Id26 { get; set; }
    public int Id27 { get; set; }
    public int Id28 { get; set; }
    public int Id29 { get; set; }
    public int Id31 { get; set; }
    public int Id32 { get; set; }
    public int Id33 { get; set; }
    public int Id34 { get; set; }
    public int Id35 { get; set; }
    public int Id36 { get; set; }
    public int Id37 { get; set; }
    public int Id38 { get; set; }
    public int Id39 { get; set; }
    public int Id310 { get; set; }
    public int Id311 { get; set; }
    public int Id312 { get; set; }
    public int Id313 { get; set; }
    public int Id314 { get; set; }
    public int Id315 { get; set; }
    public int Id316 { get; set; }
    public int Id317 { get; set; }
    public int Id318 { get; set; }
    public int Id319 { get; set; }
    public int Id320 { get; set; }
    public int Id321 { get; set; }
    public int Id322 { get; set; }
    public int Id323 { get; set; }
    public int Id324 { get; set; }
    public int Id325 { get; set; }
    public int Id326 { get; set; }
    public int Id327 { get; set; }
    public int Id328 { get; set; }
    public int Id329 { get; set; }


    public int Id401 { get; set; }
    public int Id402 { get; set; }
    public int Id403 { get; set; }
    public int Id404 { get; set; }
    public int Id405 { get; set; }
    public int Id406 { get; set; }
    public int Id407 { get; set; }
    public int Id408 { get; set; }
    public int Id409 { get; set; }
    public int Id4010 { get; set; }
    public int Id4011 { get; set; }
    public int Id4012 { get; set; }
    public int Id4013 { get; set; }
    public int Id4014 { get; set; }
    public int Id4015 { get; set; }
    public int Id4016 { get; set; }
    public int Id4017 { get; set; }
    public int Id4018 { get; set; }
    public int Id4019 { get; set; }
    public int Id4020 { get; set; }
    public int Id4021 { get; set; }
    public int Id4022 { get; set; }
    public int Id4023 { get; set; }
    public int Id4024 { get; set; }
    public int Id4025 { get; set; }
    public int Id4026 { get; set; }
    public int Id4027 { get; set; }
    public int Id4028 { get; set; }
    public int Id4029 { get; set; }
    public int Id4031 { get; set; }
    public int Id4032 { get; set; }
    public int Id4033 { get; set; }
    public int Id4034 { get; set; }
    public int Id4035 { get; set; }
    public int Id4036 { get; set; }
    public int Id4037 { get; set; }
    public int Id4038 { get; set; }
    public int Id4039 { get; set; }
    public int Id40310 { get; set; }
    public int Id40311 { get; set; }
    public int Id40312 { get; set; }
    public int Id40313 { get; set; }
    public int Id40314 { get; set; }
    public int Id40315 { get; set; }
    public int Id40316 { get; set; }
    public int Id40317 { get; set; }
    public int Id40318 { get; set; }
    public int Id40319 { get; set; }
    public int Id40320 { get; set; }
    public int Id40321 { get; set; }
    public int Id40322 { get; set; }
    public int Id40323 { get; set; }
    public int Id40324 { get; set; }
    public int Id40325 { get; set; }
    public int Id40326 { get; set; }
    public int Id40327 { get; set; }
    public int Id40328 { get; set; }
    public int Id40329 { get; set; }
}


Andrus

AnswerRe: Speeding up DataGridView RowCount assignment Pin
Wendelius27-Oct-08 10:23
mentorWendelius27-Oct-08 10:23 
GeneralRe: Speeding up DataGridView RowCount assignment Pin
AndrusM27-Oct-08 10:28
AndrusM27-Oct-08 10:28 
GeneralRe: Speeding up DataGridView RowCount assignment Pin
Wendelius27-Oct-08 10:49
mentorWendelius27-Oct-08 10:49 
GeneralRe: Speeding up DataGridView RowCount assignment Pin
AndrusM27-Oct-08 23:53
AndrusM27-Oct-08 23:53 
GeneralRe: Speeding up DataGridView RowCount assignment Pin
Luc Pattyn27-Oct-08 10:33
sitebuilderLuc Pattyn27-Oct-08 10:33 
GeneralRe: Speeding up DataGridView RowCount assignment Pin
AndrusM27-Oct-08 22:58
AndrusM27-Oct-08 22:58 
GeneralRe: Speeding up DataGridView RowCount assignment Pin
Luc Pattyn27-Oct-08 23:28
sitebuilderLuc Pattyn27-Oct-08 23:28 
GeneralRe: Speeding up DataGridView RowCount assignment Pin
AndrusM28-Oct-08 0:09
AndrusM28-Oct-08 0:09 
GeneralRe: Speeding up DataGridView RowCount assignment Pin
Luc Pattyn28-Oct-08 0:31
sitebuilderLuc Pattyn28-Oct-08 0:31 
GeneralRe: Speeding up DataGridView RowCount assignment Pin
AndrusM28-Oct-08 3:30
AndrusM28-Oct-08 3:30 
Questionhow to make call to telephone in c# Pin
ramu20u27-Oct-08 9:21
ramu20u27-Oct-08 9:21 
AnswerRe: how to make call to telephone in c# Pin
MidwestLimey27-Oct-08 9:38
professionalMidwestLimey27-Oct-08 9:38 
AnswerRe: how to make call to telephone in c# Pin
PIEBALDconsult27-Oct-08 18:20
mvePIEBALDconsult27-Oct-08 18:20 
Questionproblem with creating a messagequeue Pin
prasadbuddhika27-Oct-08 9:10
prasadbuddhika27-Oct-08 9:10 
AnswerRe: problem with creating a messagequeue Pin
manfred.bjorlin27-Oct-08 9:14
manfred.bjorlin27-Oct-08 9:14 
QuestionProblems with deserialization of MessageQueue Message Pin
manfred.bjorlin27-Oct-08 9:04
manfred.bjorlin27-Oct-08 9:04 
AnswerRe: Problems with deserialization of MessageQueue Message Pin
Le centriste27-Oct-08 9:33
Le centriste27-Oct-08 9:33 

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.