How do i remove a row that is not equal to "0"? I tried this but it removes only 2 or 3 rows - datagridviewrow

// the lup that goes through every row
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (dataGridView1.Rows[0].Cells["Payment"].Value.ToString()!="0")
{
dataGridView1.Rows.Remove(row);
}

Not sure but if you are removing rows while you cycle through them, you may be skipping rows. If you delete a row and then increment your index, you may skip the next row. Would you try cycling backwards through the table like this link suggests? Similar question

Related

How to use DWitemstatus in Power Builder

I'm learning about Power Builder, and i don't know how to use these, (DWitemstatus, getnextmodified, modifiedcount, getitemstatus, NotModified!, DataModified!, New!, NewModified!)
please help me.
Thanks for read !
These relate to the status of rows in a datawindow. Generally the rows are retrieved from a database but this doesn't always have to be the case - data can be imported from a text file, XML, JSON, etc. as well.
DWItemstatus - these values are constants and describe how the data would be changed in the database.
Values are:
NotModified! - data unchanged since retrieved
DataModified! - data in one or more columns has changed
New! - row is new but no values have been assigned
NewModifed! - row is new and at least one value has been assigned to a column.
So in terms of SQL, a row which is not modified would not generate any SQL to the DBMS. A DataModified row would typically generate an UPDATE statement. New and NewModifed would typically generate INSERT statements.
GetNextModifed is a method to search a set of rows in a datawindow to find the modified rows within that set. The method takes a buffer parameter and a row parameter. The datawindow buffers are Primary!, Filter!, and Delete!. In general you would only look at the Primary buffer.
ModifedCount is a method to determine the number of rows which have been modifed in a datawindow. Note that deleting a row is not considered a modification. To find the number of rows deleted use the DeletedCount method.
GetItemStatus is a method to get the status of column within a row in a data set in a datawindow. It takes the parameters row, column (name or number), and DWBuffer.
So now an example of using this:
// loop through rows checking for changes
IF dw_dash.Modifiedcount() > 0 THEN
ll = dw_dash.GetNextModified(0,Primary!)
ldw = dw_dash
DO WHILE ll > 0
// watch value changed
IF ldw.GetItemStatus(ll,'watch',Primary!) = DataModified! THEN
event we_post_item(ll, 'watch', ldw)
END IF
// followup value changed
IF ldw.GetItemStatus(ll,'followupdate',Primary!) = DataModified! THEN
event we_post_item(ll, 'followupdate', ldw)
END IF
ll = ldw.GetNextModified(ll,Primary!)
LOOP
ldw.resetupdate() //reset the modifed flags
END IF
In this example we first check to see if any row in the datawindow has been modified. Then we get the first modified row and check if either the 'watch' or 'followupdate' columns were changed. If they were we trigger an event to do something. We then loop to the next modified row and so on. Finally we reset the modified flags so the row would now show as not being mofified.

dhtmlxgrid addRow() unusual behavior on checkbox

I am trying to add rows to a grid using dhtmlx in java, following is the code.
var combinedColumn = "displayText";
displayOptionsGrid.addRow(selectedID, [ displayOptionsGrid.getRowsNum() == 0 ? 1 : 0, combinedColumn]);
What the function is supposed to do is that if the number of rows is zero it adds the first row as checked and then the rest as unchecked. The error which I am facing is, I delete the rows one by one and try to re-add the rows in the same session with some other row at first than the row I added previously, but can't. I can only add the row which I added first previously as the first row.
When I use grid.clearAll() it works fine. Can someone tell me the exact thing we do in clearAll() which we don't in deleteSelectedRows() in dhtmlxgrid. Thanks.
Please, check your selectedID attribute.
Note that each row should have a unique id, so adding a row with the id existing in your grid will break the grid.

How can I more efficiently find the height of a table using Python

I am using openpyxl to copy data from an Excel spreadsheet. The data is a table for an inventory database, where each row is an entry in the database. I read the table one row at a time using a for loop. In order to determine the range of the for loop, I wrote a function that examines each cell in the table to find the height of the table.
Code:
def find_max(self, sheet, row, column):
max_row = 0
cell_top = sheet.cell(row = row - 1, column = column)
while cell_top.value != None:
cell = sheet.cell(row = row, column = column)
max = 0
while cell.value != None or sheet.cell(row = row + 1, column = column).value != None:
row += 1
max = max + 1
cell = sheet.cell(row = row, column = column)
if max > max_row:
max_row = max
cell_top = sheet.cell(row = row, column = column + 1)
return max_row
To summarize the function, I move to the next column in the worksheet and then iterate through every cell in that sheet, keeping track of its height until there are no more columns. The catch about this function is that it has to find two empty cells in a row in order to fail the condition. In a previous version I used a similar approach, but only used one column and stopped as soon as I found a blank cell. I had to change it so the program would still run if the user forgot to fill out a column. This function works okay for a small table, but on a table with several hundred entries this makes the program run much slower.
My question is this: What can I do to make this more efficient? I know nesting a while loop like that makes a program take longer but I do not see how to get around it. I have to make the program as foolproof as possible, so I need to check more than one column to stop user errors from failing the program
This is untested, but every time I've used openpyxl, I iterate over all rows like so:
for row in active_worksheet:
do_something_to(row)
so you could count like:
count = 0
for row in active_worksheet:
count += 1
EDIT: This is a better solution: Is it possible to get an Excel document's row count without loading the entire document into memory?
Read-only mode works row-by-row on the source so you probably want to hook it into it. Alternatively, you could pass the cells of the of a worksheet into something like a Pandas matrix which has indices for empty cells.

Is this Cover Column / Uncover Column pseudocode for Dancing Links correct?

I'm doing a project with Algorithm X (Dancing Links) and I'd like to know if the pseudocode for the column covering is correct. I've not found many pseudocodes that deal with "next Row" and "next Column" like Knuth's paper explains, so I haven't really been able to compare the rest to mine. But his paper is obviously not big on implementation details so I can't fully compare to it either.
I have something wrong in my Dancing Links code when I want to return multiple solutions (3888 for a 2x2 empty board, and it crashes with bigger boards) and everything is ""correct"" from the code's point of view, so I'm thinking maybe something about the concept is wrong.
This is the pseudocode (I know it looks like a lot but that's because I split it into 4 parts to minimize mistakes and making it easier to read, it's actually really really simple):
node::cover()
/*Does the unlinking/relinking of the Cover procedures*/
{
if this is the only visible node in the column
null its header's firstRow and lastRow pointers
else
this->previousRow sets its nextRow to this->nextRow
this->nextRow sets its previousRow to this->previousRow
if this is the first row of this->header
set this->header's first row as this->nextRow
else if this is the last row of this->header
set this->header's last row as this->previousRow
decrease this->header's amount of rows by 1
}
node::uncover()
/*Does the unlinking/relinking of the Uncover procedures*/
{
if this is the only visible node in the column
set its header's firstRow and lastRow pointers to this
else
this->previousRow sets its nextRow to this
this->nextRow sets its previousRow to this
if this->nextRow is the first row of this->header
set this->header's first row as this
else if this->previousRow is the last row of this->header
set this->header's last row as this
increase this->header's amount of rows by 1
}
node::coverRow(header H)
/*Covers the entire row.*/
{
index = this->nextNode
while index->header is different from H
index->cover()
index->nextNode
}
node::uncoverRow(header H)
/*Uncovers the entire row.*/
{
index = this->previousNode
while index->header is different from H
index->uncover()
index->previousNode
}
header::cover()
/*Covers column and calls to coverRow for each row*/
{
Set this->previousColumn as this->nextColumn
Set this->nextColumn as this->previousColumn
index = this->firstRow
if my index is not null
while index is different from lastRow
index->coverRow(this)
index = next row
lastRow->coverRow(this)
}
header::uncover()
/*Uncovers column and calls to coverRow for each row*/
{
Set previousColumn->nextColumn as this
Set nextColumn->previousColumn as this
index = this->lastRow
if my index is not null
while index is different from firstRow
index->uncoverRow(this)
index = previous row
firstRow->uncoverRow(this)
}
coverColumns(node selectedRow)
/*Gets a list of the headers (from the first node to the next node of the row) and goes through them, first to last, covering them.*/
{
get a list of the headers that are linked to that selectedRow
index = first node of the list
while index != end of the list
index->header->cover()
index = next node of the list
}
uncoverColumns(node selectedRow)
/*Gets a list of the headers (from the first node to the next node of the row) and goes through them, last to first, covering them.*/
{
get a list of the headers that are linked to that selectedRow
index = last node of the list
while index != beginning of the list
index->header->cover()
index = previous node of the list
}
The first thing you have is the selectedRow, and you have to call uncoverColumns with that as a parameter. From there I think (though, right now considering it's not working I'm not so sure) you have to get all the columns that are satisfied by that row. Once you have the three of them, you cover all their rows.
I hope the pseudocode is readable, it's the first time I've written pseudocode for someone else.
Thanks a lot in advance.
You need to do the operations in uncover in the opposite order than in cover. Currently you do them in the same order.

jqgrid column chooser returns column order based on current order not original order

I want to persist the column order via localStorage which is working. However, the column chooser gives the order of the columns based on the current order not the original order.
Example:
3 column table where 0 is first, 1 == second, 2 is last column
0,1,2
choose column order to put last column in first, order becomes
2,0,1
choose column order again and put (original last column) back into last and order becomes:
1,2,0
because it resets the column numbers based on current order rather than ORIGINAL order. How to fix this?
onClickButton: function () {
$(this).jqGrid('columnChooser', {
done : function (perm) {
if (perm) {
localStorage["OD_Table_Col_Order"] = perm;
$(this).jqGrid("remapColumns", perm, true);
}
}
});
}
I think that you can find the solution if you would use remapColumns parameter of jqGrid as additional information.
One more way would be to save in localStorage the array of name properties of colModel items instead of the indexes perm.

Resources