Click here to Skip to main content
15,905,867 members
Home / Discussions / C#
   

C#

 
AnswerRe: Reading Specific Line Pin
PIEBALDconsult28-Oct-08 11:22
mvePIEBALDconsult28-Oct-08 11:22 
QuestionHow NOT to select a cell in DGV? Pin
User 543536427-Oct-08 19:17
User 543536427-Oct-08 19:17 
AnswerRe: How NOT to select a cell in DGV? Pin
AhsanS27-Oct-08 20:52
AhsanS27-Oct-08 20:52 
GeneralRe: How NOT to select a cell in DGV? Pin
User 543536427-Oct-08 20:54
User 543536427-Oct-08 20:54 
QuestionFreehand drawing on WPF Pin
softwareengr27-Oct-08 19:14
softwareengr27-Oct-08 19:14 
AnswerRe: Freehand drawing on WPF Pin
leppie28-Oct-08 1:14
leppie28-Oct-08 1:14 
AnswerRe: Freehand drawing on WPF Pin
Pete O'Hanlon28-Oct-08 2:32
mvePete O'Hanlon28-Oct-08 2:32 
QuestionAutomating mpp using late binding Pin
DJ24527-Oct-08 18:27
DJ24527-Oct-08 18:27 
Questioncan not connect with .xls file Pin
HowIsIT27-Oct-08 17:47
HowIsIT27-Oct-08 17:47 
AnswerRe: can not connect with .xls file Pin
Parwej Ahamad27-Oct-08 18:23
professionalParwej Ahamad27-Oct-08 18:23 
GeneralRe: can not connect with .xls file Pin
HowIsIT27-Oct-08 23:12
HowIsIT27-Oct-08 23:12 
QuestionSimple screensaver crashing Pin
Data_Dragon27-Oct-08 14:00
Data_Dragon27-Oct-08 14:00 
Questionresources in solution Pin
nelsonpaixao27-Oct-08 13:10
nelsonpaixao27-Oct-08 13:10 
AnswerRe: resources in solution Pin
DaveyM6927-Oct-08 15:50
professionalDaveyM6927-Oct-08 15:50 
Questionthread abort exception when service ends to where it has been invoked from Pin
stephan_00727-Oct-08 13:04
stephan_00727-Oct-08 13:04 
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 

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.