Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Tooltips with a NumericEditArray

Hi
 
I writing an app where I'm using the NumericEditArray control to display a list of values in a double[].
 
I'd like the ability to add a tootip to each value in the array so that the user can mouseover an item in the array and a tooltip will appear displaying the channel number. To set the tooltips I would imagine using code something in the form of:

// Set the channels array to the values

double[] data = new double[40];

string[] tooltips = new string[40];

for (int i = 0; i < data.Length; i++)

tooltip[i] = "chan " + i.ToString();

this.txtChannelsArray.SetValues(data);

this.txtChannelsArray.SetTooltips(tooltips);

 
Is this functionality possible or is there any way I can acheive it? Alternatively if I could assign a label next to each value in the array this would also be a solution. Is this possible?
 
 
Thanks
 
Adam
 
0 Kudos
Message 1 of 7
(4,259 Views)
Hi Adam,
 
Yes, you can set tooltips for each item in a NumericEditArray.  The following instructions assume you are using C#.
 
  1. Drag a ToolTip from Common Controls onto the form with the NumericEditArray.
  2. Add the following code to your Form, after InitializeComponent()

int i = 0;

foreach (Control c in numericEditArray1)

{

toolTip1.SetToolTip(c,

"hello " + i.ToString());

i++;

}

Best of luck with your application!
Cheers,

David Goldberg
National Instruments
Software R&D
Message 2 of 7
(4,234 Views)
Thanks, much appreciated, works a treat
0 Kudos
Message 3 of 7
(4,226 Views)

It wasn't clear to me which constructor I needed to use to create toolTip1 in this example.  I got it working and decided to post my code.  This is a complete listing of a method that loads a NumericEditArray control called adcValues with 10 values and the assigns the tool tips. 

The empty ToolTip constructor works fine.  Maybe it's obvious but I thought I would post this anyway. 

private void button1_Click(object sender, EventArgs e)
        {
            int i = 0;
            int num_adcs = 10;
            double[] adcChannels = new double[num_adcs];

            // Fill up an array with some generic values
            for (i = 0; i < num_adcs; i++)
            {
                adcChannels[i] = i * 500;
            }

            //
            // -- START OF OPTIONAL SECTION.
            //
            // Just trying to format the NumericEditArray controls so that I don't need scroll bars to
            // see all the values.  I fixed the max at 20 just because it seemed like a good value at
            // the time.  Must have been as big as I wanted to make the dialog the control was in or
            // something.Pretty clumsy but it seems to work all right
            //

            // Make table long enough to not need scroll bars
            adcValues.Height = adcValues.ItemTemplate.Height * (num_adcs + 1);

            // Add more controls if needed
            if ((num_adcs > 1) && (num_adcs < 20))
            {
                adcValues.ScaleMode = ControlArrayScaleMode.CreateFixedMode(num_adcs);
            }
            else if (num_adcs < 1)
            {
                adcValues.ScaleMode = ControlArrayScaleMode.CreateFixedMode(1);
            }
            else
            {
                MessageBox.Show(string.Format("Problem with adcValues.  Can only display 1-20.  Only updating up to 20.  Sent = {0}", num_adcs));
                return;
            }

            // -- END OF OPTIONAL SECTION

            // Assign the array to the NumericEditArray control. It will grow as needed.
            adcValues.SetValues(adcChannels);

            // Create a ToolTip object without worrying about assigning it to anything yet.
            ToolTip toolTip1 = new ToolTip();
            i = 0;

            // Add the tool tips now to each value in the NumericEditArray control.
            foreach (Control c in adcValues)
            {
                toolTip1.SetToolTip(c, "hello " + i.ToString());

                i++;
            }
        }

Grant


Grant M. Johnson
Project Engineer
LECO Corporation
0 Kudos
Message 4 of 7
(4,213 Views)

Hi Grant,

Thanks for taking the time to post this code!  Do we have permission to make an example out of this, and post it to our Dev Zone site?  Or, if you prefer, you can post the code.

Cheers,

David Goldberg
National Instruments
Software R&D
0 Kudos
Message 5 of 7
(4,150 Views)
Hi David,

I re-posted to community.ni.com.

Grant

Grant M. Johnson
Project Engineer
LECO Corporation
0 Kudos
Message 6 of 7
(4,145 Views)
I appreciate it, Grant!
Cheers,

David Goldberg
National Instruments
Software R&D
0 Kudos
Message 7 of 7
(4,141 Views)