Handling editing an NSTableView - nsmutablearray

I have an NSTableView backed by an NSArrayController subclass. The data displays correctly in the table when the app loads, so all is good there. I want to add a new row to the table, so I created an override for addObject to handle my custom object. When called, addObject inserts the new object into the underlying array, but the new row is the last row in the table, (makes sense, I think, as its added to the end of the underlying array), but I want the new row to be inserted as the first row. So I changed my addObject to insert the new item at index 0 (insertObject:atArrangedObjectsIndex:). Now the new row is inserted as the first row and the cell in column 0 is editable (Yeah!). BUT, when I tab to the next cell (in column 1, row 0), the selection jumps to the last row in the table and makes the cell in the second column editable. Not what I want. So how do add a new first row to my table? Make it editable without the selection switching to the last row?

I found the problem. I was programmatically sorting the table as items were added. The sort kicked in after I entered a value in the editable filed.

Related

pdfmake empty row in the table

How to make the empty last table row disappear in pdfmake?I don't want to use dontBreakRows because I need text to break to next page if it overflows.
?

Excel VBA Named Range for Form Keeps Changing

I created a userform in VBA where you can add and delete records and I am using a named range to refresh the list box showing the data in the source. The issue I am running into is the named range keeps decrementing each time I delete a record. The main issue I am running into is if the record in the first row of data ($A$2) is deleted it changes the
What I want it to stay as so it does not error out when a record it deleted from A2:
=OFFSET('Carrier List'!$A$2,0,0,COUNTA('Carrier List'!$A$1:$A$1000),11)
What it changes to when a record is deleted from A2:
=OFFSET('Carrier List'!#REF!,0,0,COUNTA('Carrier List'!$A$1:$A$999),11)
I am calling this range in several functions, namely when the form is opened, when a record is added, when a record is edited, and when a record is deleted. It only causes issues when a record is deleted but it pretty much leaves the app dead in the water when that happenes.
VBA I am using
when form is opened:
Private Sub UserForm_Initialize()
Me.lstbxCurrCarrierLst.RowSource = "CarrierList"
End Sub
For the add,edit,delete functions:
Me.lstbxCurrCarrierLst.RowSource = "CarrierList"
So, is there a way I can lock the field range so it does not change OR is there another way I can set the RowSource so it stays constant as there are changes in the dataset?
Consider using Index() instead of Offset() in the range name definition. With Index() you can point to row 2 and you don't need to worry about deleting row 2.
The first Index addresses row 2 in column A, the second Index uses the row identified by the CountA function. The colon operator connects the two cells into a range.
=Index('Carrier List'!$A:$A,2):Index('Carrier List'!$A:$A,COUNTA('Carrier List'!$A$1:$A$1000))
Edit: I missed that the original named range is 11 columns wide, i.e. starts in column A and extends to column K. To do this in the named range formula, simply change the second Index() to work in column K, but keep the CountA for column A.
=Index('Carrier List'!$A:$A,2):Index('Carrier List'!$K:$K,COUNTA('Carrier List'!$A$1:$A$1000))

When a row is added to one sheet, automatically add a row to another sheet

For Example: If I add a row between rows 1 & 2 in Excel sheet 1 then how can I reflect this change automatically in sheet 2?
Sheet 1
Sheet 2
You can use VLOOKUP function for that. First column of your Spreadsheet 2 will show first column of Spreadsheet 1 , same for the 2nd column
This is your first sheet you can change content of A and B column however you want.
For the Second Sheet add following functions
Column A - =IFERROR(VLOOKUP(Sheet1!$A$1:$A$1000, Sheet1!$A$1:$B$1000, 1, false), "")
Column B - =IFERROR(VLOOKUP(Sheet1!$A$1:$A$1000, Sheet1!$A$1:$B$1000, 2, false), "")
Now all changes from Sheet 1 will be shown in Sheet 2
On a worksheet, make a list of your names and convert the list to a table by highlighting the header and the values, press CTRL+T, give your table a name. While you still have a cell in the table selected...
On the ribbon, select Data > Get & Transform > From Table
The Power Query editor will launch in a new window and you will see the table displayed. You now have a query table. Change the name of the query. When you change the name of the query in the query settings panel on the right, it will update the name of the query in the query navigation panel on the left.
Add an index column. Go to Add Column > Index Column > From 1.
Now you have a dynamic index column attached to the names column. Go to File > Close and Load To
The query editor window will close and the Load To dialogue box will be displayed. Select Table > New Worksheet, Load to Data Model > Load.
Your query table will now be displayed on a new worksheet in your workbook. You can change the formatting on the Design tab of the ribbon.
Now, any changes you make to the original table are synced, all you have to do is refresh (Data > Refresh, from the ribbon or by right-clicking on the query table).
Try it out. Add a new name to the bottom of the data table, then go to the query table, right-click > data > refresh.

How to add a new row with the same style but different object refrence

I have this table that I want to add a number of rows to it, if I used this method table.addRow(rowInTable); the data later will be inserted in the same row. I researched about it and the method does add a row but it gives the new row the same object as the old row.
I have seen this answer https://stackoverflow.com/a/17166042/7153098 but I want a better way to work with this problem.
tried to create a new row object but didn't work
XWPFTableRow newRow = new XWPFTableRow(rowInTable.getCtRow(), table);

VBA Combobox, choose item using 2nd column item

I have a UserForm containing ComboBox and items added to it (2 columns). When adding data of invoice I have button to insert data from latest invoice - to save some time.
ComboBox shows user only 1st column items and saving data using 2nd column items. When I want to copy data from last invoice it shows me error using below code. Code tries to select item using 2nd column item.
Is it possible to select proper item in 1 column using 2nd column item?
kraj_dostawcy is ComboBox name
kraj_dostawcy.List(kraj_dostawcy.ListIndex, 1) = fak_path.Offset(-1, 5)
If you use the control's BoundColumn property to set the column containing the values you want returned from it, you can just assign the cell value to the Value of the combobox, not to its List property.

Resources