opening grid to new record

Hi, How can I open a child grid to just show a new record? I don''t want to use a rowfilter Thanks

4 Replies

AD Administrator Syncfusion Team March 2, 2004 07:36 AM UTC

I think you would have to the childGrid.DataSource to an empty DataTable that allows an AddNew. If you are using 2.0.2.1 code, then you should set this.gridDataBoundGrid1.Binder.OptimizeListChangedEvent = true; If you are using 1.6.1.8, then you will have to handle CurrentCellStartEditing, and explicitly add a DataRow to your DataTable at that point.
private void gridDataBoundGrid1_CurrentCellStartEditing(object sender, CancelEventArgs e)
{
	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
	if(cc.RowIndex == this.gridDataBoundGrid1.Model.RowCount)
	{
		DataRow dr = this.dt.NewRow();
		dt.Rows.Add(dr);
	}
}


AD Administrator Syncfusion Team March 2, 2004 12:44 PM UTC

Hi, Related to this: I get an error ''there is no row at position 1" when I try to set a rowfilter and the child grid contains no rows that satisfy the filter. Shouldn''t an empty grid just drop down?my code is. : Private Sub phraseGrid1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCurrentCellShowingDropDownEventArgs) Handles phraseGrid1.CurrentCellShowingDropDown Dim width As Integer Dim height As Integer Dim dv As DataView Dim dt As DataTable Dim s As String Dim i As Integer Dim cc As GridCurrentCell = Me.phraseGrid1.CurrentCell iPhraseID = phraseGrid1.Model(cc.RowIndex, (cc.ColIndex + 7)).Text dv = Nothing dt = Nothing s = "" i = 0 If (cc.ColIndex = 1) Then Me.correctionGrid3.CurrentCell.EndEdit() Me.correctionGrid3.Binder.EndEdit() Dim bRecords As Boolean bRecords = False Me.correctionGrid3.AllowResizeToFit = False dt = Me.correctionGrid3.DataSource dt.Columns("phrase_id").DefaultValue = Me.phraseGrid1.Model(cc.RowIndex, (cc.ColIndex + 7)).Text dv = dt.DefaultView s = System.String.Format("Phrase_Id = ''{0}''", Me.phraseGrid1.Model(cc.RowIndex, (cc.ColIndex + 7)).Text) dv.RowFilter = s ElseIf (cc.ColIndex = 2) Then Me.elementGrid2.AllowResizeToFit = False dt = Me.elementGrid2.DataSource dv = dt.DefaultView s = System.String.Format("Phrase_Id = ''{0}''", Me.phraseGrid1.Model(cc.RowIndex, (cc.ColIndex + 6)).Text) dv.RowFilter = s End If End Sub >I think you would have to the childGrid.DataSource to an empty DataTable that allows an AddNew. > >If you are using 2.0.2.1 code, then you should set > > this.gridDataBoundGrid1.Binder.OptimizeListChangedEvent = true; > > >If you are using 1.6.1.8, then you will have to handle CurrentCellStartEditing, and explicitly add a DataRow to your DataTable at that point. >
>private void gridDataBoundGrid1_CurrentCellStartEditing(object sender, CancelEventArgs e)
>{
>	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
>	if(cc.RowIndex == this.gridDataBoundGrid1.Model.RowCount)
>	{
>		DataRow dr = this.dt.NewRow();
>		dt.Rows.Add(dr);
>	}
>}


AD Administrator Syncfusion Team March 2, 2004 12:46 PM UTC

The error message is ''there is no row at position 0'' rather than ''there is no row at position 1"


AD Administrator Syncfusion Team March 2, 2004 04:20 PM UTC

To handle this problem, I think you will have to use the this.gridDataBoundGrid1.Binder.OptimizeListChangedEvent = true; setting which requires 2.0.x.

Loader.
Up arrow icon