Jump to content


Photo

How to clear all data from Grid?


  • Please log in to reply
13 replies to this topic

#1 felllipeh

felllipeh
  • Members
  • 11 posts

Posted 25 January 2006 - 08:30 PM

Hello, I want to clear all row and all colls, how I do these? I try to use these:

CODE
GridLocalizar.BeginUpdate;

GridLocalizar.ClearRows;

if GridLocalizar.Columns.Count > 0 then

begin

 for i := 0 to GridLocalizar.Columns.Count - 1 do

  GridLocalizar.Columns.Delete(i);

end;

GridLocalizar.EndUpdate;


In first time works fine, but in second memory error appears in these line
GridLocalizar.Columns.Delete(i);

How I do these?

thanks for all
Fellipe H.

#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,289 posts
  • Gender:Male

Posted 27 January 2006 - 01:33 PM

Hello,

This is because Count property is decreased each time when one column is deleted, so you need to use while statement to delete all columns:

CODE
while Grid1.Columns.Count > 0 do

begin

 Grid1.Columns.Delete(0);

end;


or simply call Grid1.Columns.Clear;

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 felllipeh

felllipeh
  • Members
  • 11 posts

Posted 27 January 2006 - 01:48 PM

Thanks Boki, I not view these propertie...

I have other question... when I have more columns like 10... and I use keyboard to navigate in these cells, in my form appears only 3 columns (for example) others column is hide, bt when I click in Vertical bar appears to me, but when I use keyboard doesnt appers... the vertical bar doesn't move to see the selected cell, its a bug or I make code to see cell active?

thanks for your patience.. biggrin.gif

#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,289 posts
  • Gender:Male

Posted 27 January 2006 - 01:55 PM

Hello Fellipe,

Yes I see it, I will fix it now.

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 felllipeh

felllipeh
  • Members
  • 11 posts

Posted 27 January 2006 - 02:16 PM

QUOTE (Boki)
Hello Fellipe,

Yes I see it, I will fix it now.

regards


In time,

in SelectCell I put these code to works these:
CODE
GridLocalizar.ScrollToColumn(GridLocalizar.Columns.Item[ACol]);

Its work fine, but there oder problem... when I back to the first column, not appear completed, some space not show..

please, post the code to correct these bug, :wink:

in time... when you post download to Delphi 2005? biggrin.gif:D


thanks

#6 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 27 January 2006 - 02:17 PM

Hi,

With this kind of deletions the following also works great:

CODE
for i := Pred(GridLocalizar.Columns.Count) downto 0 do

  GridLocalizar.Columns.Delete(i);


This way you never get into problems with the decreasing count property.
G.W. van der Vegt

#7 felllipeh

felllipeh
  • Members
  • 11 posts

Posted 27 January 2006 - 02:47 PM

QUOTE (wvd_vegt)
Hi,

With this kind of deletions the following also works great:

CODE
for i := Pred(GridLocalizar.Columns.Count) downto 0 do

  GridLocalizar.Columns.Delete(i);


This way you never get into problems with the decreasing count property.


Hello wvd_vegt, this problem is resolved, Grid.Columns.Clear, is more fast.. biggrin.gif

But I have other problem, see upper.. :wink:


thanks

#8 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,289 posts
  • Gender:Male

Posted 27 January 2006 - 03:07 PM

Hello,

I have fix first problem. Open NxCustomGridControl.pas (in SourcesNext Grid) and find TNxCustomGridControl.ScrollToColumn method.

Comment next line:

CODE
//  if ColLeft - PullBack < 0 then PullBack := 0;


regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#9 felllipeh

felllipeh
  • Members
  • 11 posts

Posted 27 January 2006 - 06:12 PM

Hello Boki,

I change this but not work.. I recompile and nothing...

the two problem is here...
sad.gif

#10 felllipeh

felllipeh
  • Members
  • 11 posts

Posted 27 January 2006 - 06:12 PM

Hello Boki,

I change this but not work.. I recompile and nothing...

the two problem is here...
sad.gif

here the code

CODE
procedure TCustomGridViewControl.ScrollToColumn(AColumn: TCustomColumn);

var

 ColLeft, Space, Diff, PullBack: Integer;

begin

 ColLeft :=  AColumn.Left - HorzScrollBar.Position;

 Space := GetBodyRect.Right - GetBodyRect.Left;

 Diff := (Space - (ColLeft + AColumn.Width));

 if ColLeft = 0 then Exit;

 if ColLeft < 0 then

 begin

   HorzScrollBar.Position := AColumn.Left;

   Exit;

 end;

 PullBack := HorzScrollBar.Position - Diff;

 //if ColLeft - PullBack < 0 then PullBack := 0;

 if ColLeft + AColumn.Width > Space then HorzScrollBar.Position := PullBack;

end;


#11 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,289 posts
  • Gender:Male

Posted 27 January 2006 - 08:52 PM

Hello,

Can you please send me one small test project onto my email please.

I have made test project for this and after I comment this line, all work fine.

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#12 felllipeh

felllipeh
  • Members
  • 11 posts

Posted 27 January 2006 - 09:33 PM

QUOTE (Boki)
Hello,

Can you please send me one small test project onto my email please.

I have made test project for this and after I comment this line, all work fine.

regards


Hello Boki, to solve these error I make these modification

in line:
HorzScrollBar.Position := AColumn.Left;

I change to
HorzScrollBar.Position := AColumn.Left - 30;

Now works fine! biggrin.gif

Now I have one tip to you Boki

When I press END, automatic goes to last Row, but in real is not good as when I press END go to last Column and CTRL+END go to last row? Like DBGrid?

thanks

#13 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,289 posts
  • Gender:Male

Posted 27 January 2006 - 09:47 PM

Hello,

Please correct this line to:

CODE
HorzScrollBar.Position := AColumn.Left - GetBodyRect.Left;


This is it smile.gif
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#14 felllipeh

felllipeh
  • Members
  • 11 posts

Posted 30 January 2006 - 02:14 PM

Thanks Boki,

Works fine now!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users