GtkTreeView, select/unselect row - treeview

I have a simple TreeView with some entries and I need to receive a signal when a row is selected or unselected and retrieve the selected model's content.
def on_row_select(tree):
model, iter = tree.get_selection().get_selected()
print(model[iter][0])
...
treeview.connect('cursor-changed', on_row_select)
It works fine with selecting; however, when the row is unselected I expected iter to be None (according to manual), but the iter of previously selected element is given instead.
How can I check whether the row was uselected?

Related

Is it possible to add New Row at the certain position in the jqGrid

I have requirement of adding a new row for the button onclick.
Example
In the first row at the last cell. I have an ADD MORE button. If I click that button new row should be added below that first row.
Is it possible in jqGrid ??
Yes it is possible. The method addRowData has the needed parameters:
addRowData(string rowid, mixed data, [string position], [string
srcrowid])
Inserts a new row with id = rowid containing the data in data (an
object) at the position specified (first in the table, last in the
table or before or after the row specified in srcrowid). The syntax of
the data object is: {name1:value1,name2: value2…} where name is the
name of the column as described in the colModel and the value is the
value.
More on the method you can read in the Gurrido jqGrid documentation

How to apply a common dropdown value on multiple selected rows in a Webix datatable

I need a help on applying common drop down values to multiple selected rows in a Webix datatable. Let's say I want to select all the rows of my datatable (by Ctrl+click) for which the 'Name' column has value as 'Mark' and then want to apply a common color for them (for example : green) by clicking so that it gets applied on all the rows at one go.
The snippet is here : https://webix.com/snippet/1162ccd1
Any help on how can this be achieved would be appreciated.
Thanks in advance.
Further to this post, I am including a re-phrased and a half-way solution below for the experts to dispel any confusion about the requirement :
It does not necessarily have to be those rows which have 'Name' as 'Mark'. I put it that way to give an example. Basically, it could be any randomly selected row either consecutive or haphazard and selecting a common value for them from the drop down of the 'color' column (it could be any color in that drop down ) so that its value gets assigned to those cells of those selected rows. Note, selecting a color should not change the color of the row, so there is no css effect I want here.
I have so far written the code like below, which is able to fetch the selected rows.
rows = $$("mytable").getSelectedId(true);
for (i in rows) {
id = rows[i];
item = $$("mytable").getItem(id);
/* below effect has to happen from the drop down of data table gui */
item.id2 = "green"; //for example, it could be any value
}
Can anybody please help me in:
i) how can I apply the value selected from the drop down of data table to all the selected rows ?
ii) Secondly, how can I trigger this code ( through which event ?) once they are selected in the data table and the value is chosen from the drop down ?
Thanks.
You can do something like this by adding the onBeforeFilter event, and track only color filter ("id2" in your snippet):
onBeforeFilter: function(id, value, config) {
if (id === "id2") {
const selected = this.getSelectedId(true);
const color = this.getFilter("id2").value;
for (let row in selected) {
const item = this.getItem(selected[row]);
item["id2"] = color;
this.updateItem(item.id, item);
}
}
}
Sample is here https://webix.com/snippet/538e1ca0
But I think this is not the best way.
You can also create a context menu that is displayed by right-clicking on the table and making a choice of values in it.

NSArrayController select inserted indices after insertion not reflected in NSTableView

I have two NSTableViews both bound to their own NSArrayControllers and the user can drag & drop items from table A to table B. Now I want the dropped items in table B to be selected after insertion (so that the table can scroll to them). But it's not working.
The table view selection indexes are bound to the array controller indexes in IB.
Select Inserted Objects is checked on the array controllers in IB.
If I check arrayControllerB.selectedObjects it lists only the first inserted object, even if more were inserted.
Selection is never reflected in the associated table view.
Now, I could try to temporarily store the newly inserted objects in an array and then select them in the arrayControllerB via setSelectedObjects(), like this ...
func insertIndicesToTargetAC(indexSet:NSIndexSet)
{
let a = indexSet.toArray();
var tmpObjects = [AnyObject]();
for i in a
{
let sourceItem = sourceAC.arrangedObjects.objectAtIndex(i);
let obj:NSManagedObject = createNewFromSourceItem(sourceItem);
targetAC.addObject(obj);
tmpObjects.append(obj);
}
sourceAC.removeObjectsAtArrangedObjectIndexes(indexSet);
targetAC.setSelectedObjects(tmpObjects);
println("\(targetAC.selectedObjects)");
}
}
Here, setSelectedObjects() does show me the correct amount of newly inserted objects in the target AC but it still doesn't reflect the selection in the associated table view. Can somebody inaugurate me into the holy sanctuary of trivial Cocoa operations that persistently refuse to work?
I figured it out. I shall not attempt to tableView.reloadData() after the insertion. That will erase the selection.

Constant values in DataGridVIew

I have a DataGridView with 3 columns.
I need the first two columns remain constant, These columns always have to be the same and the user will not be able to enter a different value to these.
The values for the two first columns of the DGV are in textBox1 and textBox2.
I need that when the user is going to add a new row in the DGV the first two columns automatically fill with these constant values and set the focus to the third column.
Thanks in advance
If you don't want the user to edit the first two columns, just set their ReadOnly property to true:
this.dataGridView1.Columns[0].ReadOnly = true;
As for your other criteria, first set the following property to limit control of when a new row is added (ex. click of a button):
this.dataGridView1.AllowUserToAddRows = false;
Then create your own method to add new rows when needed:
private void AddNewRow()
{
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(this.dataGridView1);
row.Cells[0].Value = this.textBox1.Text;
row.Cells[1].Value = this.textBox2.Text;
this.dataGridView1.CurrentCell = row.Cells[2];
this.dataGridView1.BeginEdit(true);
}
Technically, you could do this when AllowUserToAddRows == true by handling the DataGridView.RowsAdded event and the above code slightly modified, but you'll get an annoying behavior where as soon as you enter one character into the new row, 3rd column, another new row is added and the editing cell loses focus (probably before you actually entered anything useful).

jqGrid setRowData method doesn't update hidden rows

I'm using jqGrid's filterToolbar method to let users quick search/filter the grid data. I'm using loadonce: true and datatype: local as my grid configs. I have a drop-down (select) filter type for one of my columns, which works fine.
Problem is when i try to update a row (using setRowData) that is not visible (because the filter/search result is hiding them), the row doesn't get updated when I reshow them by clearing the filter.
Any suggestions? I've tried triggering the reloadGrid event too, no luck.
Cheers
Update 1 - Reproducing the problem:
Here's how to reproduce the problem, using jqGrid's official demos:
Step 1
Browse to the jqGrid's demo page, and open the demo named 'Toolbar search' under 'New in version 3.7'
Step 2
In the demo grid, filter by the code column with the value 575878 so that only the first row is shown on the grid.
Step 3
Bring up the javascript console and update a row that's not currently visible, in this example update row 2:
jQuery("#toolbar").jqGrid('setRowData',2,{item_id:2,item:'blargh',item_cd:12345678});
Step 4
Unhide all the rows by clearing the filter value, and see that row 2 has not been updated!
Anything I'm doing wrong here? Possible workarounds?
You misunderstand how the grid are build. Grid can contain hidden columns, but no hidden rows. If one filter grid the full grid body will be removed and only the filtered rows will be inserted.
The method setRowData can be used to modify any row of the grid, but you can't modify something which is not present in the grid.
If you use local grid (datatype: 'local') then the data which you save in the grid will be saved in two internal jqGrid parameters data and _index. So you should modify the data object. To fill grid with modified data you need call .trigger("reloadGrid").
So if you want modify columns item_id, item and item_cd of the grid's data for the rowid=2 you can do the following steps.
1) Get references to the internal jqGrid parameters data and _index:
var $myGrid = jQuery("#toolbar"),
data = $myGrid.jqGrid('getGridParam', 'data'),
index = $myGrid.jqGrid('getGridParam', '_index');
2) Get reference to the object which represent the rowid which you need:
var rowId = '2',
itemIndex = index[rowId],
rowItem = data[itemIndex];
3) Modify the data item like you as need:
rowItem.item_id = 2;
rowItem.item = 'blargh';
rowItem.item_cd = 12345678;
4) Refresh grid contain (if needed) by reloading the grid
$myGrid.trigger('reloadGrid');

Resources