Why is datagrid update SO slow?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • VM

    Why is datagrid update SO slow?

    I have a 35000 line datagrid and updating one field in all 35000 rows takes
    an eternity. How come? Since I don't have the datasource available (it may
    be a table or view), in my example I do it like this:

    for (int i=0;i<34000;i++ ) //the first 2000 records took 2 mins.
    {
    dataGrid_auditA ddress[i, 5] = "MARKED";
    }

    Any help would be appreciated.


  • Miha Markic [MVP C#]

    #2
    Re: Why is datagrid update SO slow?

    Hi,

    Well, it depends on the grid. However, why would you need 35000 records?
    What grid are you talking about? Did you try BeginUpdate/EndUpdate?
    It is a bad idea having that many records in a grid.

    --
    Miha Markic [MVP C#] - RightHand .NET consulting & development
    miha at rthand com


    "VM" <vonchi_m@yahoo .com> wrote in message
    news:e9KzVzdPEH A.2716@tk2msftn gp13.phx.gbl...[color=blue]
    > I have a 35000 line datagrid and updating one field in all 35000 rows[/color]
    takes[color=blue]
    > an eternity. How come? Since I don't have the datasource available (it may
    > be a table or view), in my example I do it like this:
    >
    > for (int i=0;i<34000;i++ ) //the first 2000 records took 2 mins.
    > {
    > dataGrid_auditA ddress[i, 5] = "MARKED";
    > }
    >
    > Any help would be appreciated.
    >
    >[/color]


    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: Why is datagrid update SO slow?

      VM,

      Well, the fact that you are performing 35000 updates is part of it. I
      would recommend actually going to the data source, updating all 35000 rows,
      then calling AcceptChanges on the table/view that they are in. This should
      make it faster.

      It would be nice if the grid supported the ability to not update itself
      during an operation, but in order to do this, you will have to detach the
      data source, update the table, and then reattach.

      Hope this helps.


      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m


      "VM" <vonchi_m@yahoo .com> wrote in message
      news:e9KzVzdPEH A.2716@tk2msftn gp13.phx.gbl...[color=blue]
      > I have a 35000 line datagrid and updating one field in all 35000 rows[/color]
      takes[color=blue]
      > an eternity. How come? Since I don't have the datasource available (it may
      > be a table or view), in my example I do it like this:
      >
      > for (int i=0;i<34000;i++ ) //the first 2000 records took 2 mins.
      > {
      > dataGrid_auditA ddress[i, 5] = "MARKED";
      > }
      >
      > Any help would be appreciated.
      >
      >[/color]


      Comment

      • VM

        #4
        Re: Why is datagrid update SO slow?

        But in the process of updating the windows datagrid I also update an ascii
        file by writing each row (in our case, 35000) to the file. And the whole
        process of opening the file, writing to it 35,000.times, and closing takes
        less than a second (almost instantaneous). So imagined it'd be almost the
        same speed.


        "VM" <vonchi_m@yahoo .com> wrote in message
        news:e9KzVzdPEH A.2716@tk2msftn gp13.phx.gbl...[color=blue]
        > I have a 35000 line datagrid and updating one field in all 35000 rows[/color]
        takes[color=blue]
        > an eternity. How come? Since I don't have the datasource available (it may
        > be a table or view), in my example I do it like this:
        >
        > for (int i=0;i<34000;i++ ) //the first 2000 records took 2 mins.
        > {
        > dataGrid_auditA ddress[i, 5] = "MARKED";
        > }
        >
        > Any help would be appreciated.
        >
        >[/color]


        Comment

        • VM

          #5
          Re: Why is datagrid update SO slow?

          It's a Windows datagrid. Basically, I use the grid to load the file to it,
          modify certain aspects of the file through the grid, and write the grid to
          the file. These files are usually HUGE and our goal is to be able to do this
          with 1.6 million records (which means 1.6m rows). So 35,000 isn't that many
          considering what we have to accomplish. And although a normal user will only
          highlight a few records and update the file with those few records, we're
          prepping up to the possibility that a user will want to highlight and modify
          all 35,000 records.

          The datagrid is mostly a visual commodity so the user knows what he has
          updated (ie. when a user highlights one record and right-clicks, the grid
          will update column X with the words "right-clicked"). Now, If we highlight
          all 35,000 records, it'll have to go to all 35,000 rows and write
          "right-clicked". That's what takes so long.

          It was either the grid or a listview.

          Angel

          "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
          news:#KKQE5dPEH A.628@TK2MSFTNG P11.phx.gbl...[color=blue]
          > Hi,
          >
          > Well, it depends on the grid. However, why would you need 35000 records?
          > What grid are you talking about? Did you try BeginUpdate/EndUpdate?
          > It is a bad idea having that many records in a grid.
          >
          > --
          > Miha Markic [MVP C#] - RightHand .NET consulting & development
          > miha at rthand com
          > www.rthand.com
          >
          > "VM" <vonchi_m@yahoo .com> wrote in message
          > news:e9KzVzdPEH A.2716@tk2msftn gp13.phx.gbl...[color=green]
          > > I have a 35000 line datagrid and updating one field in all 35000 rows[/color]
          > takes[color=green]
          > > an eternity. How come? Since I don't have the datasource available (it[/color][/color]
          may[color=blue][color=green]
          > > be a table or view), in my example I do it like this:
          > >
          > > for (int i=0;i<34000;i++ ) //the first 2000 records took 2 mins.
          > > {
          > > dataGrid_auditA ddress[i, 5] = "MARKED";
          > > }
          > >
          > > Any help would be appreciated.
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • VM

            #6
            Re: Why is datagrid update SO slow?

            How can I get the datasource from a datagrid?
            I was thinking of getting the datasource, be it a dataview or datatable,
            cast it, and then do all the necessary changes. Since I don't know what the
            source may be, I don't want to write some code for a datatable and even more
            code if it's a dataview.


            "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
            message news:urGWr5dPEH A.3988@tk2msftn gp13.phx.gbl...[color=blue]
            > VM,
            >
            > Well, the fact that you are performing 35000 updates is part of it. I
            > would recommend actually going to the data source, updating all 35000[/color]
            rows,[color=blue]
            > then calling AcceptChanges on the table/view that they are in. This[/color]
            should[color=blue]
            > make it faster.
            >
            > It would be nice if the grid supported the ability to not update[/color]
            itself[color=blue]
            > during an operation, but in order to do this, you will have to detach the
            > data source, update the table, and then reattach.
            >
            > Hope this helps.
            >
            >
            > --
            > - Nicholas Paldino [.NET/C# MVP]
            > - mvp@spam.guard. caspershouse.co m
            >
            >
            > "VM" <vonchi_m@yahoo .com> wrote in message
            > news:e9KzVzdPEH A.2716@tk2msftn gp13.phx.gbl...[color=green]
            > > I have a 35000 line datagrid and updating one field in all 35000 rows[/color]
            > takes[color=green]
            > > an eternity. How come? Since I don't have the datasource available (it[/color][/color]
            may[color=blue][color=green]
            > > be a table or view), in my example I do it like this:
            > >
            > > for (int i=0;i<34000;i++ ) //the first 2000 records took 2 mins.
            > > {
            > > dataGrid_auditA ddress[i, 5] = "MARKED";
            > > }
            > >
            > > Any help would be appreciated.
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Khalid Ashraf

              #7
              Re: Why is datagrid update SO slow?

              Why dont you only update the file and just refresh the grid, instead of
              modifying grid rows. Refreshing grid should reflect the modified data.

              "VM" <vonchi_m@yahoo .com> wrote in message
              news:uUCjsAePEH A.3220@TK2MSFTN GP09.phx.gbl...[color=blue]
              > But in the process of updating the windows datagrid I also update an ascii
              > file by writing each row (in our case, 35000) to the file. And the whole
              > process of opening the file, writing to it 35,000.times, and closing takes
              > less than a second (almost instantaneous). So imagined it'd be almost the
              > same speed.
              >
              >
              > "VM" <vonchi_m@yahoo .com> wrote in message
              > news:e9KzVzdPEH A.2716@tk2msftn gp13.phx.gbl...[color=green]
              > > I have a 35000 line datagrid and updating one field in all 35000 rows[/color]
              > takes[color=green]
              > > an eternity. How come? Since I don't have the datasource available (it[/color][/color]
              may[color=blue][color=green]
              > > be a table or view), in my example I do it like this:
              > >
              > > for (int i=0;i<34000;i++ ) //the first 2000 records took 2 mins.
              > > {
              > > dataGrid_auditA ddress[i, 5] = "MARKED";
              > > }
              > >
              > > Any help would be appreciated.
              > >
              > >[/color]
              >
              >[/color]


              Comment

              Working...