Sorry about this simple question but I'm new to UltraWinGrid. I have a unbound grid and trying to define columns, headers and adding rows from code.
I have placed my code in the initializeLayout event of the grid :
e.Layout.Bands[0].Columns.Add("col1");
e.Layout.Bands[0].Columns.Add("col2");
How to add rows ? What I'm expecting is a member of the band-class to craete a new row and the set the values or create a new row, adding cells and adding this new row to the band. But UltraGridRow has no public constructor and the band has no member to generate a row ?
Thanks for any help. Markus
Hello,
Several ways to do so, the one i use is as follow, just declare a data tabel and bind that table to the grid.
Sample:
DataTable dt = new DataTable();
dt.Columns.add("col1");
DataRow dr = dt.newRow();
dt.Rows.add(dr);
this.ultraGrid1.DataSource = dt;
- This will bind the data table with the grid and an empty single row will also be added in the grid. If you want to add row that already had some values, do the following
dr["col1"] = "Hello World";
this.ultraGrid1.Refresh();
- During runtime whenever u want to add new row, just create new row, add it to the data table and refresh ur grid.
Ok, I have to use datatable.
One more question about adding rows : In some cases the user must add new rows in a way that for every existing row a second row must be added (flat grid). After that every second row looks empty. How can I achieve this ? Can rows be inserted ?
Ooops. Sorry I have found it :
dataTable.Rows.InsertAt( row, index );
That should work for me.
Thanks anyway. Markus
The grid MUST have a data source in order to function, but it does not have to be a data table. If you are not using a database and just want to populate the grid manually, it's probably more efficient to use UltraDataSource as the data source of your grid.