I have an NSTableView
of content type View Based
with two columns.
My objects are structured as follows:
Table View
Table Column
Table Cell View
Text Field
Table Column
Table Cell View
Popup Button
For a selected row, I want to get an element inside the selected row for a specific column. Specifically, I want to get the Text Field
in the first column for the selected row.
I have an outlet to the table view and I have the index of the selected row so far, but that's about it:
- (void)getSelectedTextField
{
NSInteger selected = [tableView selectedRow];
}
Any ideas on how I can go about tackling this problem?
Edit: This is what I am trying to do: I want to change the text field to be in an editing state and focus on it so the user can start editing the text field value as soon as it is selected
Use the SelectedRows property. To enable users to select rows, you must set the SelectionMode property to FullRowSelect or RowHeaderSelect. Use the SelectedColumns property. To enable users to select columns, you must set the SelectionMode property to FullColumnSelect or ColumnHeaderSelect.
You can get the selected cells, rows, or columns from a DataGridView control by using the corresponding properties: SelectedCells, SelectedRows, and SelectedColumns. In the following procedures, you will get the selected cells and display their row and column indexes in a MessageBox. Use the SelectedCells property.
first you shall specify a variable (e.g:flg_sel) for table control attribute "w/SelColumn" . second ,you shall judge whether flg_sel = 'X' in you source code ,when flg_sel ='X' ,indicate that row was selected .
Approach: We will use a basic DOM operation in JavaScript to access table row element. We will be adding highlight class to the row that we click, if the highlight class is already present then we will remove this class to make it normal.
I seemed to have solved my own problem:
- (void)getSelectedTextField
{
NSInteger selected = [tableView selectedRow];
// Get row at specified index
NSTableCellView *selectedRow = [tableView viewAtColumn:0 row:selected makeIfNecessary:YES];
// Get row's text field
NSTextField *selectedRowTextField = [selectedRow textField];
// Focus on text field to make it auto-editable
[[self window] makeFirstResponder:selectedRowTextField];
// Set the keyboard carat to the beginning of the text field
[[selectedRowTextField currentEditor] setSelectedRange:NSMakeRange(0, 0)];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With