Im trying to create a dynamic grid with columns equal to the amount of days in a month (will add that feature later after i get the grid to appear) and rows equal to the amount of objects within the emplist list.
This is my code so far.
Grid dategrid = new Grid();
dategrid.Width = 400;
dategrid.HorizontalAlignment = HorizontalAlignment.Left;
dategrid.VerticalAlignment = VerticalAlignment.Top;
dategrid.ShowGridLines = true;
dategrid.Background = new SolidColorBrush(Colors.DimGray);
List<ColumnDefinition> columnlist = new List<ColumnDefinition>();
List<RowDefinition> rowlist = new List<RowDefinition>();
for (int i = 0; i < 31; i++)
{
columnlist.Add(new ColumnDefinition());
dategrid.ColumnDefinitions.Add(columnlist[i]);
}
for (int i = 0; i < Control.empList.Count; i++)
{
rowlist.Add(new RowDefinition());
dategrid.RowDefinitions.Add(rowlist[i]);
rowlist[i].Height = new GridLength(45);
}
The code compiles, but no grid appears on the form.
I feel like I'm missing something real basic here, but can't for the life of me figure it out.
You're missing dategrid.Bind()
Your code doesn't show you adding the grid to the page anywhere. So far all you have shown is instantiating a building the grid in memory. You need something like gridSpace.controls.add(datagrid) where gridspace is a container on the page. Something like <div id="gridspace" runat="server"></div> (any other container will do...). Or (if this is winforms) to a panel or other container on the form....
Related
I want to check all/ only certain Checkboxes as checked.
I tried various versions from stackoverflow but none seem to work out.
The code is called directly after dynamically creating the datagrid as I only want to load the Data once. - Datagrid is created in my Form_Load
The value of the Checkboxes are changed but not displayed.
//This is how i create the Datagrid column - not question relevant
for (int kacnt = 1; kacnt <= Ei.Kaanzahl; kacnt++)
{
DataGridViewCheckBoxColumn Kachk = new DataGridViewCheckBoxColumn();
Kachk.HeaderText = "Kamera" + kacnt;
Kachk.Width = 70;
WarDataGridView.Columns.Add(Kachk);
}
// The code I actually have problems with - the display of the value
foreach (DataGridViewRow row in WarDataGridView.Rows)
{
for (int col = 1; col < WarDataGridView.ColumnCount; col++)
{
(WarDataGridView.Rows[row.Index].Cells[col] as DataGridViewCheckBoxCell).Value = true;}}
Set your columns' True and False values like so:
Kamerachk.TrueValue = true;
and
Kamerachk.TrueValue = false;
I am working in c# and i am under a situation where i have a grid (childGrid) and inside this grid i want to create 3 more grids dynamically.
I want to achieve it using arrays. My try to do this is:
Grid[] row = new Grid[counts]; //counts=3 in my case but decde dynamically.
for (int i = 0; i < counts; i++)
{
row[i].RowDefinitions.Add(new RowDefinition());
}
I do so because i have one childGrid (parent grid) on that i will have 3 containers (3 more grid as container as child of chidGrid) so it is row[i] in my case (for i :0 to <3) (if you see the code). and on row[0]. i have a checkbox and two different UIelements at row[1 & 2] . I take different containers because if i select the check of row[0](checkbox) it will set the opacity of row[1].opacity=0.5; and on unchecking it will do row[2].opacity=0.5;. So thats why i have different 3 grids container on a grid.
the line row[i].RowDefinitions.Add(new RowDefinition()); gives warning.
The object reference is not set to an instance of an object.
How to achieve this ? I can not do statically because i dont know statically the value of counts(which i assumed 3 here)
You didn't actually create any grids before you tried to add rows to them.
Grid[] row = new Grid[counts];
for (int i = 0; i < counts; i++)
{
row[i] = new Grid();
row[i].RowDefinitions.Add(new RowDefinition());
}
If I interpret your question correctly, the proper way to set all the rows to a default value is not to add them, but to set them.
for (int i = 0; i < counts; i++)
{
row[i].RowDefinitions[counts] = new RowDefinition();
}
How can I plus all values of one selected row of a gridview in C# asp.net application?
For example I have a gridview in which is only one row. Values of this row are only number. So I want to plus this numbers.
I tried this loop but it writes all gridview numbers(it isn't summing them).
for (int i = 2; i < GridView1.Columns.Count; i++)
{
int x = 0;
x += int.Parse(GridView1.Rows[0].Cells[i].Text);
Response.Write(x.ToString());
}
I think you should approach this from a different perspective. The GridView is just a display control and doesn't 'hold' the data it is displaying. You are trying to use data that it really doesn't contain using a 'screen scrape' approach. You should be looking to the DataSource you bound to the grid in the first place and using the data there.
For example:
List<YourObjectWithTheNumbers> lst = something;
yourGridView.DataSource = lst;
ViewState["YourData"] = lst; // you could use Session instead: Session["YourData"]
So at this point your data is bound and saved for later use so now just update your numbers and rebind to the GridView again:
List<YourObjectWithTheNumbers> lst =
(List<YourObjectWithTheNumbers>)(ViewState["YourData"]);
int rowTotal = 0;
rowTotal += lst[0].Field1;
rowTotal += lst[0].Field2;
//etc...
yourLiteral.Text = rowTotal.ToString();
At this point you are using the actual data, not pulling it out of the grid that should be used for display purposes. It's also more secure in that you can keep the data source securely stored on the server if necessary (don't use ViewState if this is a concern) so that it can't be manipulated.
In HTML GridView render as table , better you can use Jquery to add the values ,
var total=0;
$('#gridview1').find('tr td').each(function(i, td){
var data= parseInt( $(td).val());
total+=data;
});
I created method in which I had loop and it worked !!!!!!!
public int Sum()
{
int z = 0;
int i;
int x = 0;
for (i = 0; i < GridView1.Columns.Count; i++)
{
x += int.Parse(GridView1.Rows[0].Cells[i].Text);
}
return x;
}
It was #N4TKD idea. Thanks to you !!!!
I have one form and inside form i have one toolstrip control, and i am adding ToolStripMenuItem dynamically.
What i want is when one is filled up, items should list in next row.
I tried this for increasing the height and width of form but adding items in new row not happening.
ToolStripItemCollection t_col = toolStripTaskBar.Items;
int _howMany = t_col.Count;
Rectangle mi_bounds = t_col[_howMany - 1].Bounds;
if (this.Width < (mi_bounds.X + mi_bounds.Width))
{
int minimumFormHeight = 80;
this.MinimumSize = new Size((mi_bounds.X + mi_bounds.Width), minimumFormHeight);
}
Let me know if you not understand what i want.
Any suggestion how can i achieve this.
Thank You.
You can use LayoutStyle property of ToolStrip. You need to set up it to Table and modify layout settings (specify rows and columns count).
You can do it like this:
this.toolStrip1.LayoutStyle = ToolStripLayoutStyle.Table;
var layoutSettings = (this.toolStrip1.LayoutSettings as TableLayoutSettings);
layoutSettings.ColumnCount = 3;
layoutSettings.RowCount = 3;
And the you can add new items to toolstrip:
var item = new ToolStripMenuItem(string.Format("item{0}", this.toolStrip1.Items.Count + 1));
this.toolStrip1.Items.Add(item);
I use excel to paint a pic as follow:
please pay attention to the area hightlight in red
my question is:
how to bind the datatable to legend in mschart?
so , except the legend color, also people can see the detail data from the legend.
or, you guys can tell is it feasible to bind in mschart?
Thanks in advance!
As far as I know there is nothing in the API that allows you to simply "bind" your DataTable to a legend.
But you should still be able to manage something like that with some code:
var l = chart1.Legends[0];
l.LegendStyle = LegendStyle.Table;
l.TableStyle = LegendTableStyle.Tall;
l.BorderColor = Color.OrangeRed;
l.Docking = Docking.Bottom;
l.LegendStyle = LegendStyle.Table;
l.HeaderSeparator = LegendSeparatorStyle.DashLine;
l.HeaderSeparatorColor = Color.Red;
var firstColumn = new LegendCellColumn();
l.ColumnType = LegendCellColumnType.SeriesSymbol;
l.CellColumns.Add(firstColumn);
var secondColumn = new LegendCellColumn();
l.ColumnType = LegendCellColumnType.Text;
secondColumn.Text = "#SER";
l.CellColumns.Add(secondColumn);
foreach (DataRow row in dt.Rows)
{
var column = new LegendCellColumn();
column.ColumnType = LegendCellColumnType.Text;
column.HeaderText = row["x"].ToString();
column.Text = "#VALY";
l.CellColumns.Add(column);
}
However, my suggestion would be to include the data in a separate control, rather than as part of the chart itself. It would be much easier to work with if you kept it in one of the .net controls that's meant for tabular data, whether you're in winforms or webforms.