Board index » cppbuilder » Unwanted highlighted cells in a grid

Unwanted highlighted cells in a grid

Using the grid example uploaded to borland.public.attachments for model
railroads, I am to the point of saving and loading files, which of
themselves appears to come out Ok.

However, upon clicking the Open button (or double clicking the file name) of
the open dialog box, wherever the mouse is pointing at that instant, after
the file is finished loading all the grid cells are highlighted (in blue) in
a rectangle from cell 0,0 (except 0,0 itself) to the mouse pointer as the
lower right corner.

Clicking anywhere on the grid removes the highlighting, but would really
like it to not show up at all.  Have tried using DrawGrid1->Invalidate() and
DrawGrid1->Perform(WM_LMOUSEDOWN,0,0) but to no avail.

How can I get that selected retangle out of there programatically?

Thanks

Richard

 

Re:Unwanted highlighted cells in a grid


Been a while since I have done this so here is the basics
Use the OnDrawCell method
The program paints each cell on at a time.
Change the canvas brush color to the color desired
the paint the cell.
Quote
Richard Gratias wrote:
>Using the grid example uploaded to borland.public.attachments for model
>railroads, I am to the point of saving and loading files, which of
>themselves appears to come out Ok.

>However, upon clicking the Open button (or double clicking the file name) of
>the open dialog box, wherever the mouse is pointing at that instant, after
>the file is finished loading all the grid cells are highlighted (in blue) in
>a rectangle from cell 0,0 (except 0,0 itself) to the mouse pointer as the
>lower right corner.

>Clicking anywhere on the grid removes the highlighting, but would really
>like it to not show up at all.  Have tried using DrawGrid1->Invalidate() and
>DrawGrid1->Perform(WM_LMOUSEDOWN,0,0) but to no avail.

>How can I get that selected retangle out of there programatically?

>Thanks

>Richard

Re:Unwanted highlighted cells in a grid


Quote
"Richard Gratias" <rgrat...@sk.sympatico.ca> wrote in message

news:3e91e57e@newsgroups.borland.com...

Quote
> Using the grid example uploaded to borland.public.attachments
> for model railroads, I am to the point of saving and loading files,
> which of themselves appears to come out Ok.

Are you referring to the sample I created for you?

Quote
> However, upon clicking the Open button (or double clicking
> the file name) of the open dialog box, wherever the mouse is
> pointing at that instant, after the file is finished loading all the grid
> cells are highlighted (in blue) in a rectangle from cell 0,0
> (except 0,0 itself) to the mouse pointer as the lower right corner.

What does your actual source code look like?  Please post a sample which
reproduces the problem that people can actually look at.  Since my earlier
sample did not have any open dialog, I can't reproduce your problem with my
earlier code.

Gambit

Re:Unwanted highlighted cells in a grid


"Remy Lebeau (TeamB)" <gambi...@yahoo.com> wrote in message
news:3e91fc7c@newsgroups.borland.com...

Quote

> "Richard Gratias" <rgrat...@sk.sympatico.ca> wrote in message
> news:3e91e57e@newsgroups.borland.com...
> > Using the grid example uploaded to borland.public.attachments
> > for model railroads, I am to the point of saving and loading files,
> > which of themselves appears to come out Ok.

> Are you referring to the sample I created for you?

Yes.

Quote

> > However, upon clicking the Open button (or double clicking
> > the file name) of the open dialog box, wherever the mouse is
> > pointing at that instant, after the file is finished loading all the
grid
> > cells are highlighted (in blue) in a rectangle from cell 0,0
> > (except 0,0 itself) to the mouse pointer as the lower right corner.

> What does your actual source code look like?  Please post a sample which
> reproduces the problem that people can actually look at.  Since my earlier
> sample did not have any open dialog, I can't reproduce your problem with
my
> earlier code.

> Gambit

Remy, the revisions I made to your sample include:
-- creating an integer array I call GridArray whose elements are initialized
to -1 in the constructor
-- Grid Array is set to the imagelist index number in OnDrawCell thus,
        GridArray[Row][Col] = CellData[Row][Col].ImageIndex;
-- writing the save and load functions as follows

void TForm1::SaveFilBtn() {
    if(GridSavDlg->Execute()) {
    GridSavDlg->FileName = ChangeFileExt(GridSavDlg->FileName, ".dpr");
    ofstream outfile(GridSavDlg->FileName.c_str());
     for(int x = 0; x < DrawGrid1->ColCount; ++x) {
      for(int y = 0; y < DrawGrid1->RowCount; ++y)
          outfile << GridArray[y][x] << " "; } IsDirty = false; }  }

void __fastcall TForm1::OpnFilBtnClick(TObject *Sender) { if(CanClose()) {
  if(GridOpenDlg->Execute()) { if(!FileExists(GridOpenDlg->FileName))
   MessageBox(0, "Unable to open file", "File Error", MB_OK |
MB_ICONEXCLAMATION);
   else { Caption = " D I S P A T C H E R   P A N E L  ---  " +
    UpperCase(GridOpenDlg->FileName);
    TCursor oldCursor = Screen->Cursor; Screen->Cursor = crHourGlass;
    ifstream infile(GridOpenDlg->FileName.c_str());
     for(int x = 0; x < DrawGrid1->ColCount; ++x) {
      for(int y = 0; y < DrawGrid1->RowCount; ++y) {
       infile >> CellData[y][x].ImageIndex;
       GridArray[y][x] = CellData[y][x].ImageIndex;
       DrawGrid1->Perform(WM_LBUTTONDOWN, 0, 0); }  }
    DrawGrid1->Perform(WM_LBUTTONDOWN, 0, 0); DrawGrid1->Invalidate();
    IsDirty = false; Screen->Cursor = oldCursor; } } }  }

RowCount and ColCount are both set at 200 right now.

The second last line must look really strange but I needed it to even get as
far as I did.

Outside of the above, the only other main change I made that I can think of
is right button clicks now rotate image in grid cell 90 deg each click
(counterclockwise)

I notice there never seems to be attachments to the newsgroup posts, but if
you would like Remy I would be very happy to zip everything up and send it
to you (directly?) if it might appear there is something else I have not
mentioned causing the difficulty.

Sure appreciate all this effort on my behalf very very much.

Richard

Re:Unwanted highlighted cells in a grid


Not sure if I should be posting another note further down or here, but will
try here first.  Was the last post I sent adequate to investigate the
problelm or should I have perhaps included some further details?

See my previous post on April 7 about 2:49 pm (on my list anyway) for the
code snippets passed along.

When one has to use examples out of books etc. so much as I do and ends up
attempting to combine parts from different sources, I can fully appreciate
how easily I may have messed up -- maybe on something that would not even
occur to me as being relevant to the disucussion.

I have been helped so much already on this project I am reluctant to impose
any further, but I would be interested in knowing what I must have done
wrong, and maybe even how to overcome the difficulty.

Can't overemphasize how much I appreciate what has been done for me already.

Richard

Quote
> > "Richard Gratias" <rgrat...@sk.sympatico.ca> wrote in message
> > news:3e91e57e@newsgroups.borland.com...
> > > Using the grid example uploaded to borland.public.attachments
> > > for model railroads, I am to the point of saving and loading files,
> > > which of themselves appears to come out Ok.

> > Are you referring to the sample I created for you?

> Yes.

> > What does your actual source code look like?  Please post a sample which
> > reproduces the problem that people can actually look at.  Since my
earlier
> > sample did not have any open dialog, I can't reproduce your problem with
> my
> > earlier code.

> > Gambit

Other Threads