I'm confused by this part dataGrid.DataSource = dataTable.DefaultView;
Why isn't it like datagrid.datasource = datatable
Also, I have a few pet peves about your code here, just some advice. don't ever name variables after class names, you shouldn't rely on case senstivity to tell the difference bettween (datatable and DataTable), this just makes things un readable (which c....).
Also, why are you going though all this trouble Do you have any control of the business object Do you create the business object Are you getting it from someone else If you control it why not just build it as a datatable to begin with, if you don't and there is some other reason for this, then check out this link on how to bind arrays and such to the grid, you can even bind classes but they must inherit and be constructed just right.
this is wht i'm doing. the user is not able to edit the grid i.e. he is not able to edit the content of grid. its like the grid is in read only mode. i hope this helps
Can you give a bit more information here All of us have datagrids that edit datatables so I'm sure I speak for most of us when we ask for a little more information.
I can assume though, that maybe you are editing the data and it's not getting reflected at the database, is this the issue
cannot edit DataGrid columns when dataSource is DataTable
cannot edit DataGrid columns when dataSource is DataTable
Presanna
dataGrid.DataSource = dataTable.DefaultView;
Why isn't it like
datagrid.datasource = datatable
Also, I have a few pet peves about your code here, just some advice.
don't ever name variables after class names, you shouldn't rely on case senstivity to tell the difference bettween (datatable and DataTable), this just makes things un readable (which c....).
Also, why are you going though all this trouble Do you have any control of the business object Do you create the business object Are you getting it from someone else If you control it why not just build it as a datatable to begin with, if you don't and there is some other reason for this, then check out this link on how to bind arrays and such to the grid, you can even bind classes but they must inherit and be constructed just right.
http://www.syncfusion.com/FAQ/WinForms/FAQ_c43c.asp#q818q
http://www.c-sharpcorner.com/Code/2004/June/ObjectDataGridBinding.asp
http://www.dotnet247.com/247reference/msgs/55/278257.aspx
Hope it helps
Daniel J Segan
private void FillGrid(DataGrid dataGrid,IList businessData)
{
DataTable dataTable = new DataTable(dataGrid.Name);
DataColumn dataColumn = null;
DataRow dataRow = null;
BusinessObject businessObj = new BusinessObject();
if(businessData.Count!= 0)
{
businessObj = (BusinessObject) businessData[0];
foreach(PropertyInfo property in
businessObj.GetType().GetProperties())
{
dataColumn = new DataColumn(property.Name,property.GetType());
dataColumn.ReadOnly = false;
dataColumn.AllowDBNull = true;
dataTable.Columns.Add(dataColumn);
}
businessObj = null;
foreach(BusinessObject businessObject in businessData)
{
dataRow = dataTable.NewRow();
foreach(PropertyInfo property in
businessObject.GetType().GetProperties())
{
Object propertyValue = property.GetValue(businessObject,null);
if(propertyValue != null)
{
dataRow[property.Name] = propertyValue;
}
}
dataTable.Rows.Add(dataRow);
}
dataGrid.ReadOnly = false;
//dataGrid.DataSource = businessData;
dataTable.DefaultView.AllowEdit = true;
dataGrid.DataSource = dataTable.DefaultView;
}
Steve Miller
I can assume though, that maybe you are editing the data and it's not getting reflected at the database, is this the issue