This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

GUI Composer - Displaying strings in Dgrid

I have been unable to find a way to display strings in Dgrid.  I have no trouble creating the column label in the target with:

const char *programLabels [3] = {"ID", "Delay Value", "Description"} ;    //  for the Dgrid widget Column Names field;

However, if I use the TI recommended method for binding to a char array for the Dgrid widget Data field (from the wiki on "Binding to an array of C Strings") where I am trying to bind the variable names to the field using:

char = names[] = {"John", "Peter", "Alex"};  //  Dgrid Data Values

The Dgid displays  a letter J in the first column, an o in the second column and a h in the third column of the table.  Obviously not what I need.  What am I doing wrong?  What is the correct way of getting a string into Dgrid.  If this is not possible can someone post the documentation on the gc.dijit.Dgrid widget with a description of any methods for setting and getting data into the grid.  This is only useful if I can set string values into the widget.

is there a preprocessing or post processing fix to this problem?

BTW, Dgrid works fine for displaying integer values using a statement like:

int dataValue[3][3] = {{1,2,3}}, {4,5,6},{7,8,9}};  

However, I have been unable to coerce it into displaying strings.  Any help with a description of the c code for getting a string into the grid would be most appreciated.

Thanks again for your help. 

  • GUI Composer currently does not support binding to two dimensional string arrays.

    It is possible to use multiple "GUI Vars" to bind to each of the array's row, which itself is one dimensional string array. 

    When the value of each of the "GUI Vars" changes, you can make it set the corresponding Grid raw to its value.

    Of course this solution assumed that the first dimension of the array does not change. 

    Regards

    Dobrin

  • Dobrin:
    Thank you for your response. However, I'm afraid I don't quite understand your answer. The use of multiple GUI Vars makes sense to me. However you state that when the value of the Gui Vars changes "make it set the corresponding grid value." Exactly how do I do this? I assume this is accomplished in the onPropertyChanged function in app.js. Is it accomplished by using a digit.byId(widget_id).set(value, "String") kind of statement? I understand how to do this for a text box but not Dgrid. Could you possibly provide a complete example for setting at least one row in Dgrid?

    Also, you state that "this solution assumes that the first dimension of the array does not change." I'm not sure what your are referring to here. Could you please explain this.

    Thanks in advance for your help.

    Dan
  • Here is an example of binding a two dimensional string array in GUI Composer.

    Here is how I declared my two dimensional strings in my C program:

    char* twoDimCharArray [2][2] = {{"A0","A1"},{"B0","B1"}};

    In GUI Composer

    Add a DGrid

    Change its id to “mygrid”.

    Do not bind the grid to anything, do not change any other property.

    Add two GUI Vars: “row0” and “row1”.

    Set their data type to “Array”.

    Add OnPropertyChange to both GUI Vars: “onRow0PropertyChanged” and “onRow1PropertyChanged”.

    Here is the content of app.js. Note that I added two global variables “grid” and “data”.

    Before we set the data of the grid we need to set its columns in “ready” callback.

    var data = [["",""],["",""]];

    var grid;

    require(["dojo/ready"], function(ready){

        ready(function(){

    grid =  dijit.byId('mygrid');

    grid.set("columns",["X","Y"]);

        });

    });

    function onRow0PropertyChanged( propertyName, newValue, oldValue) {

    data[0] = newValue;

    grid.set('data',data);

    }

    function onRow1PropertyChanged( propertyName, newValue, oldValue) {

    data[1] = newValue;

    grid.set('data',data);

    }

  • Sorry, forgot to mention that GUI Var "row0" should be bound to "twoDimCharArray[0]" and "row1" should be bound "twoDimCharArray[1]".
  • >>>>> Also, you state that "this solution assumes that the first dimension of the array does not change." I'm not sure what your are referring to here. Could you please explain this.

    Hi Dan,
    You can see in my example that the number of GUI Vars is the first dimension of the String array. Each of the GUI Vars binds to the corresponding row in the array: row0 <--> twoDimCharArray[0], row1 <--> twoDimCharArray[1]. This means that the dimension of twoDimCharArray itself should not change dynamically. You don't want during the program execution twoDimCharArray to start pointing to a new string array that is [3][3]. If that happens the third row will not be shown in the grid since nothing is bound to it.
    Regards
    Dobrin
  • Dobrin:
    Thank you so much for your help. Your example is perfect and my problem is solved.

    Best wishes,

    Dan