LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I get checkbox behavior in a column of a table?

I have a table with 11 columns. The first column needs to have a "checkbox" type of behavior. I need to start with an "X" or a checkmark. If the user clicks on the cell then I need "toggle behavior. I defined the column as a string and preset an "X" in the column for each row. Then I called a callback function which gets the value that is currently there and uses a SetTableCellVal to either show the X or display a blank. However, this does not work well because after you select the column in a particular row (cell), the cell highlights and it is not until you click on another cell in the table that you see the X disappear. Is there a better way to do this in a table? I really would like checkbox behavior in a table cell.

Thanks,
Donna
0 Kudos
Message 1 of 7
(6,448 Views)
Hi Donna,

Here's how I solved the problem:

I included toolbox.fp in the project. One of the functions in the .fp under
User Interface Utilities is Extended Mouse Events. To enable these events
use:

EnableExtendedMouseEvents (panel, control, time_interval);

Then within my callback function when I switch on the event for the table I
include:

case EVENT_LEFT_MOUSE_UP :
Point p;
GetActiveTableCell (panel, control, &p);
// Point p will (should) contain the proper column/row (p.x and p.y) you
clicked on
break;

Best of luck,
George Hodgson

"donna" <x@no.email> wrote in message news:169068@exchange.ni.com...
> I have a table with 11 columns. The first column needs to have a
"checkbox" type of behavior. I need to start with an "X" or a checkmark.
If the user clicks on the cell then I need "toggle behavior. I defined the
column as a string and preset an "X" in the column for each row. Then I
called a callback function which gets the value that is currently there and
uses a SetTableCellVal to either show the X or display a blank. However,
this does not work well because after you select the column in a particular
row (cell), the cell highlights and it is not until you click on another
cell in the table that you see the X disappear. Is there a better way to do
this in a table? I really would like checkbox behavior in a table cell.
<br><br>Thanks,<br>Donna


0 Kudos
Message 2 of 7
(6,450 Views)
George,
Thank you so much for your reply. I used your suggestion and it works well with one exception and I wonder if you can help me with this?

I have two panels on this menu.
Panel 1 contains the table with the column that I want to have "X"s or blank.I have another panel on the same window and when I click on a button on the other panel which sets all of values to "X" on my panel with the table
0 Kudos
Message 3 of 7
(6,442 Views)
George,
Thank you so much for your reply. I used your suggestion and it works well with one exception and I wonder if you can help me with this?

I have two panels on this menu.
Panel 1 contains the table with the column that I want to have "X"s or blank.
Panel 2 contains a button which sets all of the values to "X".

After I select the button on Panel 2 to provide X's then I see the following behavior in my table column with the X's in Panel 1:

I need to left click the column twice. The first time just highlights the cell and then the second time will provide the toggle behavior. Also once I am in this mode, I can click anywhere in the table even though I have provided checks for the cell.x value.

It might be important to note that I defined the EnableExtendedMouseEvents in a local function.
Thanks so much,
Donna
0 Kudos
Message 4 of 7
(6,440 Views)
Donna,

I neglected to add a bit more code that I use in my callback. As you've
probably noticed tables in CVI exhibit quirky behaviour at times and the
snippet below eliminates some of that (but not all). I have a small app that
has an interactive year calendar with 12 tables where I need to capture the
date (cell) clicked on in order to present information to the user. It seems
that CVI (or perhaps Windows) doesn't process/update the active table cell
until after the callback event EVENT_LEFT_CLICK is issued. By waiting for
EVENT_LEFT_MOUSE_UP the system has time to correctly establish which cell
was clicked on.

It's possible that ProcessSystemEvents() will also work but I haven't tried
that.

One other thing - if the table Control Mode is 'Indicator' this will not
work - another quirk I guess. Also notice that although you can specify the
Control Mode for individual cells, it really doesn't do anything of value. I
believe this is a bug in CVI.

Here's the snippet:

int CVICALLBACK tableCB (int panel, int control, int event,
void *callbackData, int eventData1,int eventData2)
{
Point p;
static short click = 0;

switch (event) {
case EVENT_LEFT_CLICK :
// this establishes that the mouse was clicked on a table
click = 1;
break;
case EVENT_LEFT_MOUSE_UP :
if (!click) return 0;
click = 0;
switch (control) {
case PANEL_TABLE1 :
GetActiveTableCell(panel,table,&p);
// Note if p.x or p.y == 0 then not on a valid cell
break;
// repeat case for each table
}
}
}

Best regards,
George Hodgson

"donna" <x@no.email> wrote in message news:169127@exchange.ni.com...
> George,<br>Thank you so much for your reply. I used your suggestion and it
works well with one exception and I wonder if you can help me with this?
<br><br>I have two panels on this menu. <br>Panel 1 contains the table with
the column that I want to have "X"s or blank.<br>Panel 2 contains a button
which sets all of the values to "X".<br><br>After I select the button on
Panel 2 to provide X's then I see the following behavior in my table column
with the X's in Panel 1:<br><br> I need to left click the column twice.
The first time just highlights the cell and then the second time will
provide the toggle behavior. Also once I am in this mode, I can click
anywhere in the table even though I have provided checks for the cell.x
value.<br><br> It might be important to note that I defined the
EnableExtendedMouseEvents in a local function.<br>Thanks so much,<br>Donna


0 Kudos
Message 5 of 7
(6,436 Views)
You can use a picture of a checked check box and a picture of an unchecked check box, and toggle between them when the cell is clicked, or the spacebar is hit.

I've attached a simple sample program.

- jared
Message 6 of 7
(6,412 Views)

I've created a library which does this little image trick to give you easy checkboxes.

 

I went a step further and created the checkbox images from within CVI itself by creating checkbox controls on a hidden panel, copying them to a bitmap handle, and then using them in runtime.

 

If you're interested, let me know.

0 Kudos
Message 7 of 7
(3,018 Views)