i get an error (non-invocable member-- can't be used like a method) any help?
-
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
if (row.Cells(this.invoiceNO.Index).Value == true)
{
a.Add(row.Cells(this.invoiceNO.Index).Value);
}
} -
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
if (row.Cells(this.invoiceNO.Index).Value == true)
{
a.Add(row.Cells(this.invoiceNO.Index).Value);
}
}In C#, you access array elements using [] not (),
if (row.Cells[this.invoiceNO.Index].Value == true)
This will access the elements, instead of invoking it as a function. Indexers (C# Programming Guide)[^] Methods (C# Programming Guide)[^]
The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
-
In C#, you access array elements using [] not (),
if (row.Cells[this.invoiceNO.Index].Value == true)
This will access the elements, instead of invoking it as a function. Indexers (C# Programming Guide)[^] Methods (C# Programming Guide)[^]
The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
many thanks...but i get another error (Operator '==' cannot be applied to operands of type 'object' and 'bool')
-
many thanks...but i get another error (Operator '==' cannot be applied to operands of type 'object' and 'bool')
Member 12899746 wrote:
Operator '==' cannot be applied to operands of type 'object' and 'bool'
That simply means you need to cast it to boolean value first and then apply == operator, try,
if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
There are many other ways to solve this, read, c# - Error 7 Operator '==' cannot be applied to operands of type 'object' and 'bool' - Stack Overflow[^]
The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
-
Member 12899746 wrote:
Operator '==' cannot be applied to operands of type 'object' and 'bool'
That simply means you need to cast it to boolean value first and then apply == operator, try,
if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
There are many other ways to solve this, read, c# - Error 7 Operator '==' cannot be applied to operands of type 'object' and 'bool' - Stack Overflow[^]
The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
Or better, omit the test altogether:
if ((bool)row.Cells[this.invoiceNO.Index].Value)
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
Or better, omit the test altogether:
if ((bool)row.Cells[this.invoiceNO.Index].Value)
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
There are 2 more ways to do this, in SO thread. ;-)
The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
-
Member 12899746 wrote:
Operator '==' cannot be applied to operands of type 'object' and 'bool'
That simply means you need to cast it to boolean value first and then apply == operator, try,
if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
There are many other ways to solve this, read, c# - Error 7 Operator '==' cannot be applied to operands of type 'object' and 'bool' - Stack Overflow[^]
The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
it's work......... manythanks