PDA

View Full Version : create groupcommands dynamically



oscar_nadie
Mar 30, 2011, 12:54 PM
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

oscar_nadie
Apr 09, 2011, 9:03 PM
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!