S
Steven Line
Based on this post from Clay Burch and the SyncFusion FAQ website, I
tried to disable my add new row at the bottom of my datagrid. However
the add new row still shows up. When I click on it my app crashes. Can
anybody look at the routine I've included at the bottom and tell me what
I did wrong?
Thanks,
Steve
Clay's Post:
You can do this by getting at a dataview associated with the datagrid,
and
setting its AllowNew member. Here is one way you can do this.
CurrencyManager cm =
(CurrencyManager)this.BindingContext[dataGrid1.DataSource,
dataGrid1.DataMember];
//no adding of new rows
((DataView)cm.List).AllowNew = false;
===================================
Clay Burch
Syncfusion, Inc.
My Routine:
private void loadMessagesDataGrid(ref DataTable msgsDataTable)
{
DateTime startDateTime = DateTime.Now.AddDays(-1);
string messagesSelectStr = "SELECT id, fldtimestamp, "+
"payload, direction, state, transNum, port "+
"FROM messages "+
"WHERE port = "+Port+" "+
"AND fldtimestamp > #"+startDateTime+"# "+
"ORDER BY fldtimestamp DESC";
// Create data adapter objects
MessagesDataAdapter = new OleDbDataAdapter(messagesSelectStr,
Db.getConnection());
MessagesDataAdapter.TableMappings.Add("Table1", "messages");
createMessagesInsertAndUpdateCommands(MessagesDataAdapter, Db);
try
{
MessagesDataAdapter.Fill(dgDataSet, "messages");
}
catch (Exception ex)
{
Log.WriteLine("Exception Filling messagesDataAdapter: "+ex.Message);
return;
}
DataGridTableStyle messagesStyle = null;
try
{
messagesStyle = new DataGridTableStyle();
messagesStyle.MappingName = "messages";
}
catch (Exception ex)
{
Log.WriteLine("Exception getting DataGridTableStyle: "+ex.Message);
return;
}
// HERE IS THE FIRST LINE SUGGESTED BY SYNCFUSION
CurrencyManager cm = (CurrencyManager)BindingContext[dgDataSet,
"messages"];
try
{
int numCols = dgDataSet.Tables["messages"].Columns.Count;
DataGridColoredTextBoxColumn aColumnTextColumn ;
for(int i = 0; i < numCols; ++i)
{
aColumnTextColumn = new DataGridColoredTextBoxColumn(this);
aColumnTextColumn.HeaderText =
dgDataSet.Tables["messages"].Columns.ColumnName;
aColumnTextColumn.MappingName =
dgDataSet.Tables["messages"].Columns.ColumnName;
if(i == 1) // fldtimestamp
{
aColumnTextColumn.Format = "g";
}
messagesStyle.GridColumnStyles.Add(aColumnTextColumn);
}
messagesStyle.GridColumnStyles["fldtimestamp"].Width = 110;
messagesStyle.GridColumnStyles["payload"].Width = 250;
messagesStyle.GridColumnStyles["direction"].Width = 0;
messagesStyle.GridColumnStyles["state"].Width = 75;
messagesStyle.GridColumnStyles["transNum"].Width = 0;
messagesStyle.GridColumnStyles["port"].Width = 0;
messagesDataGrid.TableStyles.Clear();
messagesDataGrid.TableStyles.Add(messagesStyle);
// HERE IS THE SECOND LINE SUGGESTED BY SYNCFUSION
((DataView)cm.List).AllowNew = false;
}
catch (Exception ex)
{
Log.WriteLine("Exception setting up TableStyles: "+ex.Message);
return;
}
// bind messages data grid with messages data table
try
{
msgsDataTable = dgDataSet.Tables["messages"];
messagesDataGrid.DataSource = msgsDataTable;
msgsDataTable.DefaultView.Sort = "fldtimestamp DESC";
}
catch (Exception ex)
{
Log.WriteLine("Exception: "+ex.Message);
}
}
tried to disable my add new row at the bottom of my datagrid. However
the add new row still shows up. When I click on it my app crashes. Can
anybody look at the routine I've included at the bottom and tell me what
I did wrong?
Thanks,
Steve
Clay's Post:
You can do this by getting at a dataview associated with the datagrid,
and
setting its AllowNew member. Here is one way you can do this.
CurrencyManager cm =
(CurrencyManager)this.BindingContext[dataGrid1.DataSource,
dataGrid1.DataMember];
//no adding of new rows
((DataView)cm.List).AllowNew = false;
===================================
Clay Burch
Syncfusion, Inc.
My Routine:
private void loadMessagesDataGrid(ref DataTable msgsDataTable)
{
DateTime startDateTime = DateTime.Now.AddDays(-1);
string messagesSelectStr = "SELECT id, fldtimestamp, "+
"payload, direction, state, transNum, port "+
"FROM messages "+
"WHERE port = "+Port+" "+
"AND fldtimestamp > #"+startDateTime+"# "+
"ORDER BY fldtimestamp DESC";
// Create data adapter objects
MessagesDataAdapter = new OleDbDataAdapter(messagesSelectStr,
Db.getConnection());
MessagesDataAdapter.TableMappings.Add("Table1", "messages");
createMessagesInsertAndUpdateCommands(MessagesDataAdapter, Db);
try
{
MessagesDataAdapter.Fill(dgDataSet, "messages");
}
catch (Exception ex)
{
Log.WriteLine("Exception Filling messagesDataAdapter: "+ex.Message);
return;
}
DataGridTableStyle messagesStyle = null;
try
{
messagesStyle = new DataGridTableStyle();
messagesStyle.MappingName = "messages";
}
catch (Exception ex)
{
Log.WriteLine("Exception getting DataGridTableStyle: "+ex.Message);
return;
}
// HERE IS THE FIRST LINE SUGGESTED BY SYNCFUSION
CurrencyManager cm = (CurrencyManager)BindingContext[dgDataSet,
"messages"];
try
{
int numCols = dgDataSet.Tables["messages"].Columns.Count;
DataGridColoredTextBoxColumn aColumnTextColumn ;
for(int i = 0; i < numCols; ++i)
{
aColumnTextColumn = new DataGridColoredTextBoxColumn(this);
aColumnTextColumn.HeaderText =
dgDataSet.Tables["messages"].Columns.ColumnName;
aColumnTextColumn.MappingName =
dgDataSet.Tables["messages"].Columns.ColumnName;
if(i == 1) // fldtimestamp
{
aColumnTextColumn.Format = "g";
}
messagesStyle.GridColumnStyles.Add(aColumnTextColumn);
}
messagesStyle.GridColumnStyles["fldtimestamp"].Width = 110;
messagesStyle.GridColumnStyles["payload"].Width = 250;
messagesStyle.GridColumnStyles["direction"].Width = 0;
messagesStyle.GridColumnStyles["state"].Width = 75;
messagesStyle.GridColumnStyles["transNum"].Width = 0;
messagesStyle.GridColumnStyles["port"].Width = 0;
messagesDataGrid.TableStyles.Clear();
messagesDataGrid.TableStyles.Add(messagesStyle);
// HERE IS THE SECOND LINE SUGGESTED BY SYNCFUSION
((DataView)cm.List).AllowNew = false;
}
catch (Exception ex)
{
Log.WriteLine("Exception setting up TableStyles: "+ex.Message);
return;
}
// bind messages data grid with messages data table
try
{
msgsDataTable = dgDataSet.Tables["messages"];
messagesDataGrid.DataSource = msgsDataTable;
msgsDataTable.DefaultView.Sort = "fldtimestamp DESC";
}
catch (Exception ex)
{
Log.WriteLine("Exception: "+ex.Message);
}
}