Delphi add row to stringgrid (buttons move with their assigned rows) 2 empty rows are then populated – May 22, 2003 · i have a problem cos if i have a string grid with fixed row set up, but when i click "add", the data does get inserted into the row, but there is always an additional row inserted. I think you will get the bounty on this one, but it would be nice if you could tweak that Oct 23, 2012 · Add the text to the cells like you normally would. create to strike these row but doesn't work :-( Sep 30, 2014 · First i calculate what is the total of columns width and then i'm comparing it to the string grid width. May 10, 2011 · If you select from row 3 to row 6 in a string grid thenStringGrid. GridLineWidth; if newHeight < maxheight then stringGrid. For small fonts, the height of the rows is way too big. how can I make the blanks doesn't show and my stringgrid only show the desired data? big thanks! Jan 29, 2019 · In Delphi and FreePascal/Lazarus, you can use the TStringGrid. I think that is better than adding more and more columns to keep the grid from been to wide. In Delphi I use something like: stringgrid1. StringGrid1 contains three columns; the 3rd column of which contains unique values. Button2Click(Sender: TObject); begin LoadStringGrid(StringGrid1, 'c:\temp. Grid. Canvas. 2. StringGrid1. The only thing is that in my case i have a huge string grid and each time i would have to move more than 1000 lines from one col to another and then if the user clicks undo i will have to move it back and the undeleted column will have to be repopulated. let's say I want data range from 20-08-2020 and 21-08-2020. May 4, 2007 · Möchte meine StringGrid mit dieser Funktion sortieren, das klappt auch ohne Probleme bei Integer-Werten etc. Jan 19, 2017 · In the code , Iam adding all the data of StringGrid(StrGrdLoadCSVData) to a StringList(vSortedGrid), and now iam trying to loop through the StringList to add each row to the DB, But Iam not able to insert because my is taking the values like this. Oct 30, 2018 · I can go the long way round, loop over each row, get a TRect from CellRect(col, row), then query its State for gdSelected But isn't there a quicker way to get the row number of the currently Jan 29, 2012 · Example: I have 20 rows with 20 buttons. If stRow is 2 then row 4 becomes row 6 and so on till the end of the grid. 1, I have two StringGrids - StringGrid1 and StringGrid2. Height := newHeight; stringGrid. – Ken White I want to add a column at a particular position. RowCount - 1 downto 1 do Here's my generic code to add a line into a TStringGrid:-----procedure LineAdd(); var sRowNext: Array of string; sRowPrev: Array of string; iIndex, iRow, iCol: Integer; begin iIndex := Row; RowCount := RowCount + 1; SetLength(sRowNext, ColCount); SetLength(sRowPrev, ColCount); for iCol := 0 to ColCount - 1 do sRowNext[iCol] := ''; If you want the user to be able to select a whole row at a time in the TStringGrid at run-time, set the Object Inspector property: Options - goRowSelect - to True. Selection. Button1Click(Sender: TObject); begin SaveStringGrid(StringGrid1, 'c:\temp. DefaultRowHeight:= Grid. To see a multiline text, of course we need to use a bigger number in the StringGrid's RowHeight property. g. the file also consist of data from 19-08-2020. Apr 9, 2016 · You have errors in three of the four lines of code you posted between begin and end, and two of those three lines contain errors that would prevent the code from even compiling. May 23, 2017 · I have a heavily modified control based on TStringGrid. From Greg Liefs Delphi Question and Answer web page! MULTI-LINE COLUMN HEADINGS IN A STRINGGRID: Q. This way I can fill and clear a grid with 700. I want to allow the user to make selections in this grid but restrict the selection one single row (the current row). JJJJ und dies möchte ich korrekt sortieren. Step Two: Register the New Object. 2/10. Jan 29, 2019 · In Delphi and FreePascal/Lazarus, you can use the TStringGrid. Cells[0, row] := string1; Oct 12, 2012 · The best performance will be achieved by changing your TStringGrid into a virtual grid, e. Step Three: Fill Out the New Functions and Properties. 7. Replace your TStringGrid components with TListView components, set their ViewStyle to vsReport, set up their Columns collections as needed, and then update your code as follows: Jun 10, 2020 · The index of the first row is 0 and the index of the last row is RowCount-1. Cells[0, row] := string1; Here's my generic code to add a line into a TStringGrid:-----procedure LineAdd(); var sRowNext: Array of string; sRowPrev: Array of string; iIndex, iRow, iCol: Integer; begin iIndex := Row; RowCount := RowCount + 1; SetLength(sRowNext, ColCount); SetLength(sRowPrev, ColCount); for iCol := 0 to ColCount - 1 do sRowNext[iCol] := ''; If you want the user to be able to select a whole row at a time in the TStringGrid at run-time, set the Object Inspector property: Options - goRowSelect - to True. Mar 29, 2012 · Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand Mar 12, 2011 · @David, et al. Text; string2 := Edit2. When the application runs, strings are put in the cells of the first row of the string grid. May 24, 2005 · I'm trying Lazarus as an alternative to Delphi and am having a problem adding strings to a stringgrid. a TDrawGrid in virtual mode, which will retrieve the cells content via an Event from a separated data list. The amount of columns in your TStringGrid can be changed in the Object Inspector property: ColCount. Can Row ¶ Specifies the index of the row that contains the selected cell. Row is returned as -1. canvas. user_A italy. P. I have nothing more to gain from this question, but to leave it here will do service to future Googlers. RowCount + 1; Alternatively, I can leave it until I have added all rows and then Dec 11, 2010 · The code above (not your package), works just fine - except if all entries in a row are blank the row shows as one pixel high. Insert into abc(sno,Name)values(1,welcome); Nov 11, 2011 · Adding and removing rows is then lighting fast, otherwise TStringgrid is very slooow when you have more than 5000 records. Replace your TStringGrid components with TListView components, set their ViewStyle to vsReport, set up their Columns collections as needed, and then update your code as follows: Jul 29, 2011 · here is an old tipp from SwissDelphiCenter that could help you // Save StringGrid1 to 'c:\temp. Brush. Text; row := MainForm. TStringGrid provides many properties to control the appearance of the grid, as well as events and methods that take advantage of the tabular organization of the grid in responding to user actions. Can it be the default row hight? Try this - in FillWithRandomText() drop the loops and assign a single cell (say Cells[3,3]). txt': procedure TForm1. I've tried using MouseToCell as part of OnClick, but even after setting SG. This doesn't work in Lazarus. Color := clWhite; // add this line stringgrid1. The ColumnCount property simply returns the number of columns in the array, that is why it is read-only. . RowCount; MainForm. So I thought to break the string each time that ":" char is found. Any idea how to prevent this May 15, 2013 · Each data is divided by ":" and I want add these datas into a StringGrid. FillRect (Rect); You will notice that there are some remnants from the default drawing at the left edge of the cells (not visible in the image below, I already fixed them). Sep 30, 2016 · I want to know the Row / Column of the cell that was last active when select an item from my Popup menu. Step one: Create and Object Interface section inheriting from a current FMX Object (in this case TStringGrid) and add the extra properties and functionality required. Height + stringGrid. Note: The same can be done for rows, but for now I do not know how to mix both (cols and rows) because of how to select priority, if anyone is very interested on it let me know. The StringGrid component can be found underneath the Additional Tab on the Component Palette. type TStringGridHelper = class Helper for TStringGrid and copy the above code in the Mar 8, 2017 · Use the grid's AddObject() or InsertObject() method to add an object instance of the desired TColumn-derived class, like TStringColumn. Sep 21, 2012 · Use TListView instead of TStringGrid. Implementation: When the user presses the left mouse button I am using a dirty hack: On OnMouseDown event I capture the mouse cursor and keep it on the current row. Mar 31, 2017 · It seems it answers the question. Aug 21, 2015 · @markkk: If you're using FireMonkey, you should edit your question to add that tag, so people know you're not asking about the VCL TStringGrid. At this point the program adds the lines into a StringGrid, here you can see an image as example. RowCount := stringGrid. 1 and Freepascal 2. RowCount] := 'Hoofdstad'; Dec 8, 2013 · Wonderfull!!! But if I want to store the striked status I also add a column containing a 'x'; it works fine BUT when I create form I load the stringrid value and some 'x' in column 3, I try to use that code in form. Nov 28, 2012 · AFAIK There's no property you can tweak to insert a row in some position of a StringGrid. Nov 3, 2011 · This example displays a string grid, a list box, and a button on a form. Then it simply deletes the final row. I click on button in row 3. We shouldn't have to guess which one you're using. RowCount + 1; for I := StringGrid1. rows[0][0]:='hello'; This would set the top left most cell to 'hello'. e. Nov 20, 2012 · When ading a row : newHeight := stringGrid. Jan 4, 2011 · depending on the version of Delphi your running you could also create a "class helper" so that you don't have to hardcast each time you need to insert a new row, furthermore if you define the class helper in a "utilities" unti, you can take advantage of the "hacked" string grid in all forms, frames etc. Assuming you have a first row and columns of titles, you may code it as: I: Integer; StringGrid1. TopRow ¶ Specifies the index of the first visible scrollable row in the grid. : May 9, 2016 · I'm programming in Delphi and I want to have a vertical Scrollbar that is always visible, even if the number of rows is 1 (the DefaultDrawing option is not active, i'm using Canvas to draw the cell Oct 26, 2022 · The StringGrid component is generally described as a visual representation of a grid that consists of rows and columns. Delphi StringGrid HighLight row and column. Sometimes a white line is visible just inside the cell borders. Mar 12, 2012 · I think the number of rows would be better to increase/add - that way I could keep the width of the grid to an acceptable size. Row it still returns as -1 in the PopUp menus routines Apr 20, 2022 · This code gets the StringGrid contents per row with '|' as a separator. procedure TForm1. When you add a new row, the RowCount increases, but the index of the last row is still RowCount-1. The above doesn't fully solve the focus issue even with your paint procedure addon. The amount of rows in your TStringGrid can be changed in the Object May 18, 2016 · Add a TStringGrid object to a form to present textual data in a tabular format. txt'); end; // Load StringGrid1 from 'c:\temp. so my stringgrid will return empty grid as many as the 19-08-2020 file. SetCell (col, row, value) ¶ Sets the content of a cell. How and what is the property that allow me to make String Row or cell selectable. . Nov 12, 2003 · (i want to have a unique number for each row - that I can use when I operate on the data of a row - that doesn't necessarily corespond to the row number of the selected row in the stringgrid. datas(); var iRow: integer; RowData : string; begin {get stringgrid content} for iRow := 1 to Form7. TextHeight('X') + 4; but it is not working. Style := bsSolid; // add this line stringgrid1. UIConsts' for the color's constants. 3. In fact, if a user deletes a column i have an undo button which i want to reinsert the deleted column (i'm keeping the data in an array so i can recreate the column but i don't know how to insert one in a particular position). I don't get any errors when I compile, but the lable does not appear on the stringgrid. top will give you 3 as an output value StringGrid. Cells property after incrementing the RowCount, eg: string1, string2: string; row: integer; string1 := Edit1. is at the bottom of the row you would like to make higher, and when the Split cursor comes visible, drag the mouse to the size you would like the row cells to be. It will be much faster than this IMHO. RowCount := StringGrid1. Rows ¶ Strings: Selection ¶ Indicates the boundaries of the current selection. The first line of the example on the memo becomes: Example 2. Oct 14, 2015 · An alternative. However when I click on the popup menu, the StringGrid. Row)] + stringGrid. Oct 9, 2017 · stringgrid1. , Rows 4 to 20 are moved for stRow. RowHeights ¶ Specifies row heights of the grid. I wrote this code: Aug 13, 2011 · How to automatically resize TStringGrid row (DefaultRowHeight) to match the height of the font used? I do something like . StringGrid2 als May 18, 2016 · Add a TStringGrid object to a form to present textual data in a tabular format. Dec 1, 2012 · Using Lazarus 1. To delete the current row of the grid, call the function like this: Jun 6, 2011 · I am having a StringGrid in Delphi 5 of fixed rows and Fixed Cols. So, when you are trying to use this: Form3. RowHeights[Pred(stringGrid. As I assumed, those components are redrawn by the cells. Allerdings enthalten die zu sortieren Spalten ein Datum als String im Format TT. D. i. : I am not sure: First I thought that I need to make sure that I don't try to make BitBlt read pixels that aren't there in the source bitmap, but it seems like the function is able to handle input of this kind in the most kind way there is, namely correcting for the "incorrect" input (like Copy, where you often specify MaxInt as the length of the string). Jan 16, 2019 · I am trying to add an EditBox and button (just as an example) to a Grid's Column as a child in Delphi 10. It looks fine during design-time, but completely disappears at runtime. RowCount := row + 1; MainForm. But you have to draw those bars in the OnDrawCell event. TextLayout;' to the form and 'System. How to fill cell of a string grid using custom color? Aug 22, 2010 · Then on any form you have a TStringGrid add ,AlignedTStringGrid at the end of the interface uses clause. 0. if the stringgrid widths is bigger then i add to each columns width equal portions of the blank space left. MM. bottom will give you 6 as an output value, and remaining values you can get by iterating from the top to bottom. Add a comment | 2 Answers Sorted by: Reset to default Delphi StringGrid HighLight row and column. A. At the end of the loop, the row you wish to delete has been overwritten (by the row immediately below it) and there are two copies of the final row. – Sep 22, 2020 · hi, your answer is really helpful! It did work, however I got a case like this. 000 records within a second! Share Jan 23, 2015 · @JerryDodge I Googled for an hour and couldn't find it. Cells[0,Form3. for example when i sort the rows of the grid on different criteria, these unique identifiers won't be the same with the row number where they appear May 3, 2013 · It copies the contents of each row below the one you wish to delete into the row above. That question is described and worded badly; the borders of a StringGrid are different from the borders of a cell, which is what the linked questioner was actually asking about. Also, when i delete row by row, the rows get deleted, including the fixed row. When you click the button, the strings in the current row of the grid are displayed in the list box. I'd like to display multi-line column headings in a TStringGrid. txt'); end; // Save a TStringGrid to a file procedure Nov 9, 2014 · We need to add 'Uses FMX. i have no problem if i do not set a fixed row. The column object will get added to the grid's Columns array. But at run mode I am not able to select any row or any cell. It can also be seen as a visual version of a two-dimensional array. Jan 29, 2019 · In Delphi and FreePascal/Lazarus, you can use the TStringGrid. But, you can always do a shift in code to make space in the grid for a new row. Oct 26, 2022 · The StringGrid component is generally described as a visual representation of a grid that consists of rows and columns. lgfejkv sso jrjacg qwbvlo slfvxtdx rkzret qprokr jvldxjjp hqfiu aqzhudd mmv xhlr tnn ufzl afujw