Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-06

Dropdown in stringgrid ?

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Koenraad Lelong

Hi,

I'm trying to make a "universal importer".
I have a database I want to populate/modify with data from a csv-file. The column order of the csv-file cannot be imposed. So I have to have a way to say which column of the csv-file is which field in the database.

I have a commercial application that has something like a stringgrid but the first row has dropdown's with possible field-names. I was trying to mimic this, more or less, but had issues.

Is this possible someway ? Any hints ?

Koenraad

Reply by email

Jesus Reyes A.
to Koenraad Lelong

En Tue, 02 Jun 2015 06:01:05 -0500, Koenraad Lelong escribi?:

Show quoted text 15 lines
Hi, I'm trying to make a "universal importer". I have a database I want to populate/modify with data from a csv-file. The column order of the csv-file cannot be imposed. So I have to have a way to say which column of the csv-file is which field in the database. I have a commercial application that has something like a stringgrid but the first row has dropdown's with possible field-names. I was trying to mimic this, more or less, but had issues. Is this possible someway ? Any hints ? Koenraad

In the grid such combobox is called a picklist.

1. Select the grid
2. In the Object Inspector select the columns property and click the "..." button.
3. Add some custom columns
4. Select the column where you wish to add a pick list
5. In the Object Inspector change the ButtonStyle to cbsPickList
6. In the Object Inspector select the PickList property and click the "..." button.
7. Add all options you want to this list.
8. make sure the grid is editable.

Jesus Reyes A.

Reply by email

Koenraad Lelong
to Jesus Reyes A.

Op 03-06-15 om 01:19 schreef Jesus Reyes A.:

Show quoted text 14 lines
In the grid such combobox is called a picklist. 1. Select the grid 2. In the Object Inspector select the columns property and click the "..." button. 3. Add some custom columns 4. Select the column where you wish to add a pick list 5. In the Object Inspector change the ButtonStyle to cbsPickList 6. In the Object Inspector select the PickList property and click the "..." button. 7. Add all options you want to this list. 8. make sure the grid is editable.

Thanks, just tried this, but it's not what I need.

Like I said, I want to import a csv-file. Then, using the first row, I use a picklist of fieldnames to identify which column of the csv needs to go to which field in the database.
Maybe this clarifies it better :
------------------------------------------------------- | Field2 | Field1 | | Field3 | | | <--- picklist (Field1, Field2, Field3, blank)
------------------------------------------------------- |Col0Row1|Col1Row1|Col2Row1|Col3Row1|Col4Row1|Col5Row1| |Col0Row2|Col1Row2|Col2Row2|Col3Row2|Col4Row2|Col5Row2| etc.

This means column0 should got to Field2 of the database, column1 should got to Field1 of the database and column3 should got to Field3 of the database. The rest of the columns are not needed in the database.

Koenraad.

Reply by email

Jesus Reyes A.
to Koenraad Lelong

En Fri, 05 Jun 2015 05:55:51 -0500, Koenraad Lelong escribi?:

Show quoted text 35 lines
Op 03-06-15 om 01:19 schreef Jesus Reyes A.: > > In the grid such combobox is called a picklist. > > 1. Select the grid > 2. In the Object Inspector select the columns property and click the > "..." button. > 3. Add some custom columns > 4. Select the column where you wish to add a pick list > 5. In the Object Inspector change the ButtonStyle to cbsPickList > 6. In the Object Inspector select the PickList property and click the > "..." button. > 7. Add all options you want to this list. > 8. make sure the grid is editable. > Thanks, just tried this, but it's not what I need. Like I said, I want to import a csv-file. Then, using the first row, I use a picklist of fieldnames to identify which column of the csv needs to go to which field in the database. Maybe this clarifies it better : ------------------------------------------------------- | Field2 | Field1 | | Field3 | | | <--- picklist (Field1, Field2, Field3, blank) ------------------------------------------------------- |Col0Row1|Col1Row1|Col2Row1|Col3Row1|Col4Row1|Col5Row1| |Col0Row2|Col1Row2|Col2Row2|Col3Row2|Col4Row2|Col5Row2| etc. This means column0 should got to Field2 of the database, column1 should got to Field1 of the database and column3 should got to Field3 of the database. The rest of the columns are not needed in the database. Koenraad.

So you want the picklist only in the first row. Then use something like:

// use grid's OnSelectEditor
procedure TForm1.StringGrid1SelectEditor(Sender: TObject; aCol, aRow:
Integer;
   var Editor: TWinControl);
begin
   if aRow=StringGrid1.fixedRows then begin
     Editor := StringGrid1.EditorByStyle(cbsPickList);
     // fill the picklist with field list
     TPickListCellEditor(Editor).Items.CommaText :=
'Field1,Field2,Field3,etc';
     // or TPickListCellEditor(Editor).Items.Assign(FieldList)
     // or etc
   end else
     Editor := nil; // readonly the rest of rows (or select another editor)
end;
// use grid's OnPickListSelect
procedure TForm1.StringGrid1PickListSelect(Sender: TObject);
begin
   // make something with picklist itemindex, the current grid column is
given by StringGrid1.Col
end;

Jesus Reyes A.

Reply by email

Koenraad Lelong
to Jesus Reyes A.

Op 05-06-15 om 15:45 schreef Jesus Reyes A.:

Show quoted text 56 lines
En Fri, 05 Jun 2015 05:55:51 -0500, Koenraad Lelong escribi?: > Op 03-06-15 om 01:19 schreef Jesus Reyes A.: >> >> In the grid such combobox is called a picklist. >> >> 1. Select the grid >> 2. In the Object Inspector select the columns property and click the >> "..." button. >> 3. Add some custom columns >> 4. Select the column where you wish to add a pick list >> 5. In the Object Inspector change the ButtonStyle to cbsPickList >> 6. In the Object Inspector select the PickList property and click the >> "..." button. >> 7. Add all options you want to this list. >> 8. make sure the grid is editable. >> > Thanks, just tried this, but it's not what I need. > > Like I said, I want to import a csv-file. Then, using the first row, I > use a picklist of fieldnames to identify which column of the csv needs > to go to which field in the database. > Maybe this clarifies it better : > ------------------------------------------------------- > | Field2 | Field1 | | Field3 | | | <--- > picklist (Field1, Field2, Field3, blank) > ------------------------------------------------------- > |Col0Row1|Col1Row1|Col2Row1|Col3Row1|Col4Row1|Col5Row1| > |Col0Row2|Col1Row2|Col2Row2|Col3Row2|Col4Row2|Col5Row2| > etc. > > This means column0 should got to Field2 of the database, column1 > should got to Field1 of the database and column3 should got to Field3 > of the database. The rest of the columns are not needed in the database. > > Koenraad. > So you want the picklist only in the first row. Then use something like: // use grid's OnSelectEditor procedure TForm1.StringGrid1SelectEditor(Sender: TObject; aCol, aRow: Integer; var Editor: TWinControl); begin if aRow=StringGrid1.fixedRows then begin Editor := StringGrid1.EditorByStyle(cbsPickList); // fill the picklist with field list TPickListCellEditor(Editor).Items.CommaText := 'Field1,Field2,Field3,etc'; // or TPickListCellEditor(Editor).Items.Assign(FieldList) // or etc end else Editor := nil; // readonly the rest of rows (or select another editor) end;

Hi,

It's almost what I want. Your code makes the second row behave like a picklist (1 fixed row : row #0 is fixed), so I subtracted 1 from StringGrid1.fixedRows but no luck ;-) .
I tried a few things, but I can't let the cells of the fixed row to behave like a picklist. Am I still missing something ?

Anyway, thanks very much already.

Koenraad.

Reply by email

Jesus Reyes A.
to Koenraad Lelong

En Mon, 08 Jun 2015 06:03:28 -0500, Koenraad Lelong escribi?:

Show quoted text 28 lines
> So you want the picklist only in the first row. Then use something like: > > // use grid's OnSelectEditor > procedure TForm1.StringGrid1SelectEditor(Sender: TObject; aCol, aRow: > Integer; > var Editor: TWinControl); > begin > if aRow=StringGrid1.fixedRows then begin > Editor := StringGrid1.EditorByStyle(cbsPickList); > // fill the picklist with field list > TPickListCellEditor(Editor).Items.CommaText := > 'Field1,Field2,Field3,etc'; > // or TPickListCellEditor(Editor).Items.Assign(FieldList) > // or etc > end else > Editor := nil; // readonly the rest of rows (or select another > editor) > end; Hi, It's almost what I want. Your code makes the second row behave like a picklist (1 fixed row : row #0 is fixed), so I subtracted 1 from StringGrid1.fixedRows but no luck ;-)I tried a few things, but I can't let the cells of the fixed row to behave like a picklist. Am I still missing something ? Anyway, thanks very much already.
Can't you set FixedRows:=0?, if you do that what problems do you see in
your program?

Jesus Reyes A.

Reply by email