![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Buscar | Temas de Hoy | Marcar Foros Como Leídos |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
#12
|
||||
|
||||
|
Hola Pablo.
Ahora viendo el gráfico pude entender lo que buscas hacer. La fecha a comparar entre las del archivo es la que esta en la fila cero del StringGrid y el nombre a buscar en la tabla está en la columna cero de la misma. Entonces, esta es la prueba que realicé y funciona bién: Código:
...
#include <DateUtils.hpp>
...
void __fastcall TForm1::FormCreate(TObject *Sender) {
TStringGrid *sg = static_cast<TStringGrid*>(StringGrid1);
TDate dt = Date();
AnsiString s;
sg->ColCount = 31;
sg->Cells[0][1] = "Renuevate";
sg->Cells[0][2] = "Navidades";
sg->Cells[0][3] = "Ocasion";
for(int c =DayOf(Date()); c<= DaysInMonth(Date()); c++) {
sg->Cells[c-DayOf(Date())+1][0] = DateToStr(dt);
dt=IncDay(dt,1);
}
sg->Col = 1;
sg->Row = 1;
/* Asignar evento OnSelectCell por código */
sg->OnSelectCell = StringGrid1SelectCell;
}
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State) {
TStringGrid *sg = static_cast<TStringGrid*>(StringGrid1);
if (ACol > 0 && ARow > 0 && sg->Cells[ACol][ARow] != "") {
QryTmp->Close();
QryTmp->SQL->Clear();
QryTmp->SQL->Add("SELECT * FROM CATALOG");
QryTmp->SQL->Add("WHERE NOMBRE_CATALOGO = :PNOMBRE");
QryTmp->SQL->Add("AND :PFECHA >= FECHA_DESDE AND :PFECHA <= FECHA_HASTA");
// En columna 0 estan los nombres
QryTmp->ParamByName("PNOMBRE")->AsString = sg->Cells[0][ARow];
// En fila 0 estan las fechas
QryTmp->ParamByName("PFECHA")->AsString = sg->Cells[ACol][0];
QryTmp->Open();
if (!QryTmp->IsEmpty()) {
sg->Canvas->Brush->Color = clLime;
sg->Canvas->FillRect(Rect);
sg->Canvas->TextOut(Rect.Left+1 ,Rect.top+1, sg->Cells[ACol][ARow]);
}
}
}
/* Impedir que seleccionen columna 0 o fila 0 */
void __fastcall TForm1::StringGrid1SelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect) {
CanSelect = ACol > 0 && ARow > 0;
}
...
void __fastcall TForm1::FormDestroy(TObject *Sender) {
StringGrid1->OnSelectCell = NULL;
}
Código:
NOMBRE_CATALOGO | FECHA_DESDE | FECHA_HASTA ----------------+-------------+------------ Renuevate | 07.11.2012 | 08.11.2012 Navidades | 09.11.2012 | 10.11.2012 Ocasion | 08.11.2012 | 10.11.2012 Como verás en el resultado, el pintado considera las fechas límites de la tabla en relación a la columna y de acuerdo al nombre de la fila: ![]() No olvides quitar el evento OnSelectCell desde el Object Inspector, lo asigno por código para que permita el posicionamiento en Col = 1, Row = 1. Saludos. Edito: Me olvidaba... Y si deseas que se pinten las celdas aún estando vacías, cambiá: Código:
if (ACol > 0 && ARow > 0 && sg->Cells[ACol][ARow] != "") {
// por:
if (ACol > 0 && ARow > 0) {
__________________
Daniel Didriksen Guía de estilo - Uso de las etiquetas - La otra guía de estilo .... Última edición por ecfisa fecha: 07-11-2012 a las 14:55:12. Razón: agregar comentario |
| Herramientas | Buscar en Tema |
| Desplegado | |
|
|
Temas Similares
|
||||
| Tema | Autor | Foro | Respuestas | Último mensaje |
| Conectar base de datos Firebird con base de datos Oscommerce 2.3.3 | Adriadob | Firebird e Interbase | 11 | 31-10-2012 11:28:46 |
| Ordenar datos en un StringGrid | gilberto_1126 | Varios | 2 | 22-12-2010 18:34:29 |
| StringGrid rellenar rapidamente. | byfali | Varios | 10 | 25-03-2008 00:25:19 |
| Rellenar una grilla con datos generados por el usuario | maco2007 | .NET | 11 | 05-12-2007 02:53:00 |
| Rellenar datos de tablas | sur-se | Firebird e Interbase | 1 | 11-11-2004 11:14:44 |
|