ReoGrid Forum

Fast and powerful .NET Spreadsheet Component

You are not logged in.

Announcement

This forum has been archived and no longer accepts new user registrations. Please report your questions, problems, and feedback to the issue page of ReoGrid on GitHub. Thank you for your cooperation.

https://github.com/unvell/ReoGrid/issues

#1 2015-11-12 01:39:34

CopyPaul
Member
Registered: 2015-09-21
Posts: 19

Determining if checkbox is "checked"

Jin,

I am creating checkboxes on my "Column A" when I read myy records to populate the worksheet
....
    idx++;
    aux = idx.ToString();
    str = "A" + aux;
    sheet[str] = new object[] { new CheckBoxCell(),""};

On the form closing event I'm trying to determine which checkbox (if any) was selected, and I'm doing
this according to the documentation in the Built-in Cell types

           bool checkd;
            for (int i = 0; i < sheet.MaxContentRow; i++)
            {
                str = "A" + i.ToString();
                checkd = sheet[str] as bool;
...

            }

VS is complaining that: "The as operator must be used with a reference type or nullable type ('bool' is a non-nullable value type)". Bool is indeed a non-nullable value type, so how to we check
if a checkbox is checked?  sheet[str] is a type object, how do I make it a bool, cast?

Paul

Offline

#2 2015-11-12 07:37:09

Jingwood
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: Determining if checkbox is "checked"

Wrong example code in document, it has been corrected. Thanks!

bool isChecked = (sheet[str] as bool?) ?? false;

Jing

Offline

#3 2015-11-12 15:46:06

CopyPaul
Member
Registered: 2015-09-21
Posts: 19

Re: Determining if checkbox is "checked"

No thanks are needed, thank you for the tool.

Offline

#4 2015-11-17 01:23:32

CopyPaul
Member
Registered: 2015-09-21
Posts: 19

Re: Determining if checkbox is "checked"

Sorry Jing,

I can only get to my project as time permits.

Finally I got to continue and I think there is a typo on your suggestion

bool isChecked = (sheet[str] as bool?) ?? false;

This will force isChecked to always be false. I think the statement should read

bool isChecked = (sheet[str] as bool?) ?? true | false;

Paul

Offline

#5 2015-11-19 08:23:19

Jingwood
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: Determining if checkbox is "checked"

Hi Paul, no typo there, ?? is null-coalescing operator.

bool? a = true;
MessageBox.Show(((a as bool?) ?? false).ToString());

Result: True

https://msdn.microsoft.com/en-us/library/ms173224.aspx

Offline

Board footer

Powered by FluxBB