Announcement

Collapse
No announcement yet.

DBGrid Color -row/column

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • DBGrid Color -row/column

    Hallo,

    Ich brauche ein DBGrid wo Zahlen angezeigt werden. Ich habe mit

    DBGrid->Columns->Item[x]->Color = clRed

    eine Column in rot gefarbt in Laufzeit.

    Kein problem damit. Aber was Ich will ist das Ich eine Zelle (row,column) individual von DBGrid ändern kann.

    z.B:

    row1, column1 = clRed
    row2, column3 = clGreen

    Jemand eine lösung darauf ?

    Ich habe mit RowCount() testen gemacht aber das ist nicht die richtige lösung.
    Danke,

  • #2
    Mit einer Ereignisbehandlungsroutine für OnDrawColumnCell können Sie eine benutzerdefinierte Anzeigeroutine für die Daten in den Gitterzellen bereitstellen. Die Darstellung in der Zelle erfolgt mit den Methoden der Eigenschaft Canvas.
    Christian

    Comment


    • #3
      OnDrawColumnCell

      Wie mann dass row/column aktive macht ist noch nicht ganz klär

      OnDrawColumnCell ist eine Event von DBGrid aber wie muss Ich dass Column / Row parameter
      ändern und das color aktivieren?


      Ich habe ein Delphi Beispiel gefunden wo dass cel/column mit user farben wahrend Laufzeit
      geandert werde, aber kann Ich dass umsetzen zum C++ Builder?


      Code:
          { Is current cell the focused cell? }
          if (gdFocused in State) then begin
            DBGrid1.Canvas.Brush.Color := clBlack;
            DBGrid1.Canvas.Font.Color := clWhite;
          end
      
          { Not focused, is it the target field Terms? }
          else if (Field.FieldName = 'Terms') then
            { Check field content for one of two possible values }
            if (Field.AsString = 'FOB') then
              { If field contains "FOB" paint green }
              DBGrid1.Canvas.Brush.Color := clPaleGreen
            else
              { If field contains "Net 30" paint red }
              DBGrid1.Canvas.Brush.Color := clPaleRed
          else
            { Paint non-focused and non-target cells white }
            DBGrid1.Canvas.Brush.Color := clWhite;
          { Draw the cell! }
          DBGrid1.DefaultDrawDataCell(Rect, Field, State);

      Vielen Dank,
      Zuletzt editiert von Quadran; 11.08.2007, 23:50.

      Comment


      • #4
        Entschuldiging dass Ich soviele fragen stelle aber mit dieses problem komm Ich nicht güt aus...

        Ich verstehe da ist eine Event in DBGrid dass Ich kann benutzen aber wie das
        funkioniert verstehe Ich leiter noch nicht gut.

        Er is eine event OnDrawColumnCell und eine event OnDrawDataCell,
        wass Ich wille ist dass Ich in laufzeit, in funktion von eine datawerte, die farbe
        änder.
        z.B.
        werte = -1 = clCyan
        werte = -9 = clPurple
        werte = 0 = clRed
        werte = 1->10 = clGreen

        und das fur JEDEN zelle in das DataGrid !

        muss Ich nicht OnDrawDataCell brauchen ?

        wass Ich nicht gut verstehe is wie Ich eingriffe auf eine zelle mit
        Code:
        void __fastcall TForm1::DBGrid2DrawColumnCell(TObject *Sender,
              const TRect &Rect, int DataCol, TColumn *Column,
              TGridDrawState State)
        {
        
        }
        wie solle das program alle zellen durchlaufen?
        muss ich etwas wie ein for{} programmieren mit eine Indexnummer dass die
        col/row selektiert?

        Bitte hilfe, und danke!
        Zuletzt editiert von Quadran; 15.08.2007, 11:09.

        Comment


        • #5
          Jemand eine Beispiel ?

          Comment


          • #6
            Hallo,

            Ich habe jetz ein program mit color change von dass row:

            Code:
            ploegen->Active = true;
            
            
            
            
            if (DBGrid3->DataSource->DataSet->FieldValues["CMT"] >= 1)
            {
               DBGrid3->Canvas->Brush->Color = clRed ;  // ploeg heeft minstens 1 comité
            }
            
            if (DBGrid3->DataSource->DataSet->FieldValues["CMT"] ==0)
            {
               DBGrid3->Canvas->Brush->Color = clWhite;
            }
            
            
            
            
            
            DBGrid3->DefaultDrawColumnCell(Rect,DataCol,Column,State);
            Ist dass column auch seperat zu änderen, dann kann Ich jeden zelle seperat eine andere farbe geben.

            Comment


            • #7
              ja, wie gesagt im DrawColumnCell Event

              if(DataCol==1)
              DBGrid3->Canvas->Brush->Color = clWhite;
              else if(DataCol==2)
              DBGrid3->Canvas->Brush->Color = clBlue;
              Christian

              Comment


              • #8
                Danke Sehr, es ist viel für ein Beginner,

                Ich bin schön viel weiter gekommen auf diese Forum...danke alle!

                Comment


                • #9
                  Code:
                  if(DataCol==1)
                  DBGrid3->Canvas->Brush->Color = clWhite;
                  else if(DataCol==2)
                  DBGrid3->Canvas->Brush->Color = clBlue
                  Das funkioniert güt aber wann dass möghlich ist will Ich gerne bewerkstelligen
                  dass z.B. in folgenden DBGrid mit 26 cols und 12 rows:

                  8 -1 0 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9
                  9 8 -1 -9 0 1 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9
                  8 -1 0 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9
                  7 6 9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9

                  die -1 = clWhite
                  die -9 = clPurple
                  die 0 = clRed
                  die 1->10 = clMoneyGreen

                  m.a.w. dass jeden Dateifeld seperate die farbe eingestellt werde.

                  Ist dass überhaupt möghlich?

                  Danke,
                  Zuletzt editiert von Quadran; 17.08.2007, 15:43.

                  Comment


                  • #10
                    sehe nicht das das geht
                    Christian

                    Comment


                    • #11
                      Kann Ich vielleicht ein andere Komponent brauchen für diesen Option?

                      Comment


                      • #12
                        musst du prüfen

                        http://www.tmssoftware.com/gridpack.htm
                        Christian

                        Comment


                        • #13
                          Wow! danke, dass ist viel zum nachschauen

                          Ich habe dass geprüft und dass seht güt aus. Die Preise ist auch noch nicht ganz viel für soviele
                          Komponenten. Vielleicht gehe Ich diese brauchen!

                          Danke für dass Link und deine Beitrage ...
                          Zuletzt editiert von Quadran; 18.08.2007, 08:50.

                          Comment


                          • #14
                            Dass ist eine Beispiel von www.tmssoftware.com/gridpack.htm
                            Mitt diesen muss dass gehen, denke Ich !

                            Code:
                            void __fastcall TForm1::AdvStringGrid1GetCellColor(TObject *Sender, long ARow,
                            long ACol, TGridDrawState AState, TBrush *ABrush, TFont *AFont)
                            {
                            if ((ACol==0) && (ARow>0))
                            {
                            ABrush->Color = clYellow;
                            AFont->Color = clRed;
                            AFont->Style << fsBold;
                            }
                            if ((ACol==2) && (ARow>0))
                            {
                            if (AdvStringGrid1->Cells[ACol][ARow]=="4") AFont->Color=clGreen;
                            if (AdvStringGrid1->Cells[ACol][ARow]=="6") AFont->Color=clBlue;
                            if (AdvStringGrid1->Cells[ACol][ARow]=="8") AFont->Color=clBlack;
                            if (AdvStringGrid1->Cells[ACol][ARow]=="12") AFont->Color=clRed;
                            }
                            }

                            Comment

                            Working...
                            X