Home › Forums › WinForms controls › Xceed Grid for WinForms › Dynamically changing grid
-
AuthorPosts
-
#14548 |
I created 9 unbound columns with 9 rows in the design view on a grid. Everytime i call update based on mulitple combo box values i need the 9×9 grid to clear all values in all cells, but keep the 9×9 structure. Then i will put new values into the right cells and color code them. I am having trouble with two things. I was trying to loop through each row and set the cell to string.empty, but the grid.datarows.count doesnt give me back a value. If i have created 9 Value rows, and 9 unbound columns in the designer shouldnt it have a count = 9. Also im trying to hide the column header and also row headers. I found the row headers under RowSelectorPane.visible = false. I want the grid only to shows the cells and be unselectable.
Imported from legacy forums. Posted by jspence3 (had 1925 views)
It is better to add rows at form_load, this will generate data rows instead of value rows, which is more what you want. In fact, you can set up your grid as you want at form_load :
private void Form1_Load(object sender, System.EventArgs e)
{
gridControl1.ReadOnly = true;
gridControl1.SelectionMode = SelectionMode.None;
groupByRow1.Visible = false;
columnManagerRow1.Visible = false;
dataRowTemplate1.RowSelector.Visible = false;
gridControl1.RowSelectorPane.Visible = false;Random random = new Random();
for( int i = 0; i < 9; i++ )
{
Xceed.Grid.DataRow row = gridControl1.DataRows.AddNew();
}
}Then in an update event, you can access each cell and do whatever you need on it :
//clear all cells, keeping the grid structure
private void button1_Click(object sender, System.EventArgs e)
{
for( int i = 0; i < 9; i++ )
{
Xceed.Grid.DataRow row = gridControl1.DataRows[ i ];
for( int j = 0; j < 9; j++)
{
row.Cells[ j ].Value = string.Empty;
row.Cells[ j ].ResetBackColor();
}
}
}//fill all cells
private void button2_Click(object sender, System.EventArgs e)
{
Random random = new Random();
for( int i = 0; i < 9; i++ )
{
Xceed.Grid.DataRow row = gridControl1.DataRows[ i ];
for( int j = 0; j < 9; j++)
{
row.Cells[ j ].Value = random.Next( 1000 ).ToString();
row.Cells[ j ].BackColor = Color.FromArgb( random.Next(255), random.Next(255), random.Next(255) );
}
}
}Imported from legacy forums. Posted by André (had 3175 views)
-
AuthorPosts
- You must be logged in to reply to this topic.