Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 22-06-2015
ermac ermac is offline
Miembro
NULL
 
Registrado: jun 2015
Posts: 10
Poder: 0
ermac Va por buen camino
Smile Rellenar una fila y columna dada en un TStringGrid

Tengo q hacer un programa en el cual rellene la fila y columna ingresada por el usuario

Mi codigo es el siguiente:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, ExtCtrls;

type
  TRellenar = class(TForm)
    Tabla: TStringGrid;
    Label1: TLabel;
    Fila: TEdit;
    Rellenar: TButton;
    Label2: TLabel;
    Columna: TEdit;
    Panel: TPanel;
    procedure RellenarClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Rellenar: TRellenar;

implementation

{$R *.dfm}

procedure TRellenar.RellenarClick(Sender: TObject);
var
i,j,m,n:integer;

begin
  i:= strtoint (Fila.Text);
  j:= strtoint (columna.text);
  If (i=0) or (j=0) then
    ShowMessage ('Error')
  else
  begin
    for m:=0 to Tabla.ColCount-1 do
    begin
      for n:=0 to Tabla.RowCount-1 do
        begin
          Tabla.Cells[m,0]:= '*';
          Tabla.Cells[0,n]:= '*';
        end;
    end;
  end;
end;

end.
Necesitaria saber como puedo hacer para q la fila y columna q ingresan en los edits me los relacione con los 2 for de abajo para q se rellene esa fila y columna

gracias

Última edición por nlsgarcia fecha: 23-06-2015 a las 00:09:39. Razón: Formateo y Sintaxis Delphi
Responder Con Cita
  #2  
Antiguo 23-06-2015
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola ermac.

Hay muchas variantes para lo que buscas hacer, te pongo un ejemplo simple pero bastante flexible :
Código Delphi [-]
// Permite ingresar solo números
procedure WCOnlyNumber(WC: TWinControl);
begin
  SetWindowLong(WC.Handle, GWL_STYLE,
    GetWindowLong(WC.Handle, GWL_STYLE) + ES_NUMBER);
end;

// Inicializar
procedure TForm1.FormCreate(Sender: TObject);
begin
  WCOnlyNumber(edColDes);   // edit columna desde
  WCOnlyNumber(edColHas);   // edit columna hasta
  WCOnlyNumber(edFilaDes);  // edit fila desde
  WCOnlyNumber(edFilaHas);  // edit fila hasta
end;

// Rellenar
procedure RellenaGrid(SG: TStringGrid; const cDes, fDes, cHas, fHas: Integer;
const Character: Char);
var
  f, c: Integer;
begin
  if (cDes < 0)or(fDes < 0)or(cHas >= SG.ColCount)or(fHas >= SG.RowCount) or
     (cDes > cHas) or (fDes > fHas) then
    raise Exception.Create('Error en rango');
  for c:= cDes to cHas do
    for f:= fDes to fHas do
      SG.Cells[c,f] := Character;
end;

// llamada ejemplo:
procedure TForm1.btnRellenaClick(Sender: TObject);
begin
  RellenaGrid(StringGrid1, StrToInt(edColDes.Text), StrToInt(edFilaDes.Text),
              StrToInt(edColHas.Text), StrToInt(edFilaHas.Text), '>')
end;

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #3  
Antiguo 23-06-2015
Avatar de AgustinOrtu
[AgustinOrtu] AgustinOrtu is offline
Miembro Premium
NULL
 
Registrado: ago 2013
Ubicación: Argentina
Posts: 1.858
Poder: 15
AgustinOrtu Es un diamante en brutoAgustinOrtu Es un diamante en brutoAgustinOrtu Es un diamante en brutoAgustinOrtu Es un diamante en bruto
Daniel,
Cita:
Empezado por ecfisa Ver Mensaje
Código Delphi [-]
// Permite ingresar solo números
procedure WCOnlyNumber(WC: TWinControl);
begin
  SetWindowLong(WC.Handle, GWL_STYLE,
    GetWindowLong(WC.Handle, GWL_STYLE) + ES_NUMBER);
end;
Aprovecho que estas de oferta y me llevo uno de estos
Responder Con Cita
  #4  
Antiguo 23-06-2015
ermac ermac is offline
Miembro
NULL
 
Registrado: jun 2015
Posts: 10
Poder: 0
ermac Va por buen camino
ya encontre el error, en Tabla.cells estaba asignando m y n pero despues la fila y la columna la deje constante con 0.. por eso no me escribia en la fila o columna q ingresaban.. solo tenia q reemplazar el 0 con i y con j y se solucionaba
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
mascaras de entrada para cada columna y fila de un tstringgrid DarkBlue OOP 0 04-07-2011 05:53:32
Color a una fila de un TStringGrid hmrvivas OOP 3 16-03-2008 03:11:35
Rellenar un comboBox a partir de una columna del datasource elorza Varios 2 21-12-2007 12:10:00
Borrar fila seleccionada de un componente TStringGrid JM75 OOP 3 16-11-2006 10:31:06
Mostrar siempre la última fila de un TStringGrid epuigdef Varios 0 23-12-2005 12:01:28


La franja horaria es GMT +2. Ahora son las 01:47:08.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi