Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

not-database Grid

Status
Not open for further replies.

Eli20

Programmer
Oct 30, 2003
119
MX
hi, is it possible to have a grid in a windows application that is not bound to a database?



something like the FlexGrid Control in vb6.0??

thank you very much

Eli
 
The DataGrid.DataSource is not bound directly to a database. Here are the valid data sources to set the DataSource property using SetDataBinbding() function:
-DataTable
-DataView
-DataSet
-DataViewManager
-Any component that implements the IListSource interface
-Any component that implements the IList interface
-obislavu-
 
mm... what i want is to be able to customize my grid, without having it bind to to anything.. i just want to be able to set the header text and then ill fill in my program with different values.

i want to get the MSFlexGrid from visual basic 6.0 result.

is it possible?

Eli
 
Yes, it is possible to have the MSFlexGrid. You have to use a DataTable object.
Solution 1.
Create a Datatable object and define the Columns that you want to be in the DataGrid.
Now you bind the DataGrid object to the DataTable.
If you display the grid, it will contains only the header columns.
In order to add a row in the grid you will add the row in the DataTable and refresh the DataGrid.
If you want to set/get the value of an existing cell in the grid then use m_DataGrid[row, col]


Solution 2.
Code:
System.Windows.Forms.DataGrid m_DataGrid;
m_DataGrid.TableStyles.Clear(); 
DataGridTableStyle vStyle = new DataGridTableStyle();
vStyle.AlternatingBackColor = System.Drawing.Color.Bisque;
vStyle.RowHeadersVisible = false;
vStyle.MappingName = "MyTable";
For each column that you have in a DataTable object do:
DataGridTextBoxColumn vColumnStyle= new DataGridTextBoxColumn();
vColumnStyle.TextBox.Enabled = false;
vColumnStyle.TextBox.CanFocus = false;  
vColumnStyle.NullText ="";
vColumnStyle.HeaderText = "Column01";
vColumnStyle.MappingName = "Column01";
vColumnStyle.ReadOnly =false/true;
vColumnStyle.Width = 50;
vColumnStyle.Alignment = System.Windows.Forms.HorizontalAlignment.Center;
vStyle.GridColumnStyles.Add(vColumnStyle);
Now bind the DataTable to the grid using a DataAdapter and the Fill() method on the DataTable.
The DataTable is empty and the also the grid.
As in the solution 1, add a row in the DataTable and refresh the grid object.
If you want to set/get the value of an existing cell in the grid then use m_DataGrid[row, col] 
object vCell = m_DataGrid[vRow,vColumn]; //get value of an existing cell
object vValue = "....";
m_DataGrid[vRow,vColumn]=vValue; //set the value of an existing cell
[obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top