Unknown Grid Name
#1
Posted 04 May 2005 - 04:40 AM
Is it possible to determine and then reference the SelectedColumn and SelectedRow if the grid name is unknown. I have many grids that are created at runtime, named uniquely and need to extract the cell contents.
Thanks.
#2
Posted 04 May 2005 - 02:32 PM
Here is one example that may help you:
First, you need to give unique Name for each your Grid:
- MyGrid1, MyGrid2, MyGrid3.
This is very important and Delphi will show error if 2 components have same name.
Then, you can use Components array of Form and go trough this array:
i: Integer;
aGrid: TNextGrid;
begin
for i := 0 to ComponentCount - 1 do
begin
if Components[i] is TNextGrid then
beging
aGrid = TNextGrid(Components[i]);
// now, you are able to do with grid what you like :)
end;
end;
end;
best regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#3
Posted 04 May 2005 - 02:38 PM
Shouldn't one test for the type of the component before casting it? The code otherwise gives an error when you drop any other component onto it.
Another thing to watch out for is that components dropped onto a container like a pageview's page or groupbox don't show up this way. Only components directly on the form. For the code to work you have to recurse into all components components arrays too.
#4
Posted 04 May 2005 - 02:43 PM
Yes, I will correct code in previous post.
thanks.
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#5
Posted 09 May 2005 - 01:34 AM
Regards, Jason
#6
Posted 09 May 2005 - 07:16 AM
You can use Components[] array of single TabSheet in PageControl.
When you create Grid in run-time, you need to have some link to this object. When you Insert Grid into some other control (like Page Control, Panel...) reference to this Grid will jump into Components[] array and you will be able to use it
Hope that this help, if you have some sample code or more details please tell me.
regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#7
Posted 09 May 2005 - 11:44 PM
Example code as follows:
var
aGrid, bGrid: TNextGrid;
i, j, k, l, m, GridCol, GridRow: Integer;
GridContent, CurrGrid: String;
begin
for i := 0 to ComponentCount - 1 do
begin
if Components[i] is TNextGrid then
begin
aGrid := TNextGrid(Components[i]);
GridCol := aGrid.SelectedColumn;
GridRow := aGrid.SelectedRow;
GridContent := aGrid.Cell[GridCol, GridRow].AsString;
NewSheet(GridContent);
end;
end;
with NxPageControl.ActivePage do
begin
for j := 0 to ComponentCount - 1 do
begin
if Components[j] is TNextGrid then
begin
bGrid := TNextGrid(Components[j]);
l := 0;
for k := 0 to aGrid.RowCount - 1 do
begin
if aGrid.Cell[GridCol, k].AsString = GridContent then
begin
bGrid.AddRow();
bGrid.Cell[0, l].AsString := aGrid.Cell[0, k].AsString;
bGrid.Cell[1, l].AsString := aGrid.Cell[1, k].AsString;
bGrid.Cell[2, l].AsString := aGrid.Cell[2, k].AsString;
bGrid.Cell[3, l].AsString := aGrid.Cell[3, k].AsString;
l := l + 1;
end;
end;
end;
end;
end;
end;
First for..loop determines current grid and selected cell content, taken from your example code. NewSheet procedure creates a new grid and parented tabsheet. Second loop populates new grid with filtered content from the first.
Thanks, Jason
#8
Posted 09 May 2005 - 11:52 PM
Don't realy understand
Can you please tell me what exactly you want to do and I will write complete procedure I am sure that this will help.
regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#9
Posted 10 May 2005 - 12:18 AM
I want the user to select cell content from an existing grid on a tabsheet, and filter rows with that content to a new grid on a new tabsheet of the same pagecontrol. This does work with the code example above.
What doesn't work, is running this procedure against the grid that was created by the procedure.
Does that make sense?
Jason
#10
Posted 10 May 2005 - 12:32 AM
you need first to get Active Grid:
go trough Components[] of ActivePage (TNxTabSheet). If you have only one Grid on each page, then all you need is to find first TNextGrid, set reference (aGrid) and exit from this loop:
begin
for j := 0 to ComponentCount - 1 do
begin
if Components[j] is TNextGrid then
begin
aGrid = TNextGrid(Components[J]);
end;
end;
end;
Now you need to create new NxTabSheet and place NextGrid inside it with desired settings and data.
I hope that this is it I think that you have switch some parts in your code
regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#11
Posted 10 May 2005 - 01:47 AM
Created a function with your code that tells me the current grid:
var
i: integer;
begin
with LogForm.NxPageControl.ActivePage do
begin
for i := 0 to ComponentCount - 1 do
begin
if Components[i] is TNextGrid then
begin
Result := TNextGrid(Components[i]);
end;
end;
end;
end;
Re-written the procedure code as follows:
var
aGrid, bGrid: TNextGrid;
i, j, GridCol, GridRow: Integer;
GridContent: String;
begin
// Determine Source Grid & Cell Content
aGrid := CurrentGrid();
GridCol := aGrid.SelectedColumn;
GridRow := aGrid.SelectedRow;
GridContent := aGrid.Cell[GridCol, GridRow].AsString;
// Create new tabsheet & grid (makes new grid active)
NewSheet(GridContent);
// Determine Destination Grid and Populate from Source Grid
bGrid := CurrentGrid();
i := 0;
for j := 0 to aGrid.RowCount - 1 do
begin
if aGrid.Cell[GridCol, j].AsString = GridContent then
begin
bGrid.AddRow();
bGrid.Cell[0, i].AsString := aGrid.Cell[0, j].AsString;
bGrid.Cell[1, i].AsString := aGrid.Cell[1, j].AsString;
bGrid.Cell[2, i].AsString := aGrid.Cell[2, j].AsString;
bGrid.Cell[3, i].AsString := aGrid.Cell[3, j].AsString;
Inc(i);
end;
end;
end;
This now produces an exception. Hope that this is clearer?
Thanks, Jason
:?
#12
Posted 11 May 2005 - 02:16 PM
Thanks, Jason
#13
Posted 11 May 2005 - 05:34 PM
Can you please tell me where error occur and what was error
thank you.
regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#14
Posted 11 May 2005 - 05:46 PM
I've upgraded to 3.1 (latest download, clean install) and is now reporting "EReadError Property HideGlyphs does not exist" on Application.Run.
If you can get me past that, I'll get the original error details to you.
Jason
#15
Posted 11 May 2005 - 05:49 PM
Press Ignore button in Delphi and then save project.
regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#16
Posted 11 May 2005 - 05:57 PM
It's a Debugger Exception Notification window with just an OK and Help. If I step through the code it makes reference to NxFlipPanel1.HideGlyphs but I don't use that component in the project. :?
Jason
#17
Posted 11 May 2005 - 06:01 PM
It must be this component inside your project NxFlipPanel1. Can you send me some screenshot on my email to see what you get
regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#18
Posted 11 May 2005 - 06:15 PM
"EExternalException with Message 'External exception C000001D'" when running the last FilterSelected1Click procedure above.
Jason
#19
Posted 11 May 2005 - 06:21 PM
Can you tell me where (on which line) this occur.
Or maybe will be better that you send me some small demo project to I test it by myself it will be a lot more easy.
regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#20
Posted 11 May 2005 - 06:26 PM
Thanks, Jason
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users