create groupcommands dynamically

  1. #1

    create groupcommands dynamically

    hi,

    i have a question, how can i create a groupcommand dynamically with code in c#?

    i have this code but doesn't work:

            ImageCommandColumn.Config commcol = new ImageCommandColumn.Config();
            commcol.Hidden = true;
            commcol.GroupCommands.Add(new GroupImageCommand { CommandName = "Gráfica", Icon = Icon.ChartBar });
            commcol.PrepareCommand.Fn = "prepareCommand";
            commcol.PrepareCommand.Fn = "prepareGroupCommand";
            //commcol.GroupCommands.Add(new CommandFill { });
            grd1.ColumnModel.Columns.Add(new ImageCommandColumn(commcol));
    please help me!
    pardonme for the english, i know that is bad.

    thanks
    Last edited by geoffrey.mcgill; Apr 10, 2011 at 6:51 PM. Reason: please use [CODE] tags
  2. #2

    solved it!

    i found the way to do this, and show you how i did.


    private GridPanel crearGridPanel() {
    
            string conn = @"Data Source=OSCAR\SQLEXPRESS; Initial Catalog = Banco; Integrated Security=true";
            SqlConnection objconn = new SqlConnection(conn);
            objconn.Open();
            string strconsulta = "SELECT [cl_cedula],[cl_nombre],[cl_edad],[cl_ingresosmes],[cl_tipo] FROM [CLIENTE]";
            SqlCommand objcomm = new SqlCommand(strconsulta, objconn);
            SqlDataReader objreader = objcomm.ExecuteReader();
    
            GridPanel grd1 = new GridPanel
            {
                ID = "grd1",
                Border = false,
                StripeRows = true,
                TrackMouseOver = true,
                AutoExpandColumn = "cl_cedula",
                Width = Unit.Parse("700"),
                Height = Unit.Parse("330"),
                Collapsible = true
            };
            grd1.Store.Add(crearStore(objreader));
            grd1.SelectionModel.Add(new RowSelectionModel { SingleSelect = true });
            crearColumn(objreader, grd1);
            grd1.View.Add(new GroupingView{ForceFit = true, MarkDirty = false, ShowGroupName = false,
                          HideGroupedColumn = true, StartCollapsed = true
            });
            objconn.Close();
            return grd1;
        }
    
        private void crearColumn(SqlDataReader objreader, GridPanel grd1)
        {
            for (int x = 0; x < objreader.FieldCount; x++)
            {
                Column.Config col = new Column.Config();
                col.ColumnID = objreader.GetName(x).ToString();
                col.Header = objreader.GetName(x).ToString().Substring(3);
                col.DataIndex = objreader.GetName(x).ToString();
                grd1.ColumnModel.Columns.Add(new Column(col));
            }
            CommandColumn commcol = new CommandColumn();
            commcol.Hidden = true;
            GridCommand grdcomm = new GridCommand();
            grdcomm.CommandName = "SelectGroup";
            grdcomm.Icon = Icon.TableRow;
            grdcomm.Text = "Grafica";
            CommandFill comf = new CommandFill();
            commcol.Commands.Add(comf);
            commcol.GroupCommands.Add(grdcomm);
            grd1.ColumnModel.Columns.Add( commcol);
        }
    
        private Store crearStore(SqlDataReader objreader)
        {
            Store store = new Store { ID = "store1", GroupField = "cl_tipo" };
            JsonReader reader = new JsonReader();
            reader.IDProperty = "ID";
            for (int z = 0; z < objreader.FieldCount; z++) {
                reader.Fields.Add(objreader.GetName(z).ToString());
            }
            store.Reader.Add(reader);
            store.DataSource = objreader;
            store.DataBind();
            store.Render();
            return store;
        }
    i hope this code help someone.

    Suerte!

Similar Threads

  1. [CLOSED] Create a textfield dynamically
    By wisdomchuck in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: May 24, 2012, 8:14 PM
  2. [CLOSED] I create dynamically control
    By trieu.tran in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Apr 05, 2012, 5:53 AM
  3. How to create dynamically Menupanel
    By krishna in forum 1.x Help
    Replies: 1
    Last Post: Mar 31, 2011, 5:37 AM
  4. Create portlet dynamically
    By vimaln in forum 1.x Help
    Replies: 3
    Last Post: Mar 13, 2009, 7:59 PM
  5. How to Create a portlet dynamically?
    By mohan.kantipudi in forum 1.x Help
    Replies: 0
    Last Post: Jan 16, 2009, 2:11 AM

Posting Permissions