473,545 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataSet - Errors editing rows after using InsertAt() - DataGrid Bo

I tried posting this in the WinForm forum and got no hits so I am
trying it here.

After inserting a new data row to a DataTable that is bound to a
datagrid, I am unable to change data in a row that is after the newly
added row without getting bizarre results.

I have added the full code for the test below. Create a project drop
in the code and run. There is nothing crazy about the code. I used
the designer to add the dataset and to do the binding.

Any help would be appreciated.

Cheers,
Dave
Test #1
=============== =======
1) Click on the row where ID = 1
2) Click "Add Row" button
3) Click on the cell ID = 2 Number = 4
4) Change the number from 4 to 5
5) Move off the row (i.e. hit the down arrow key)
6) Notice there are 2 rows with ID = 2 now
2, 5, 6
2, 4, 6
Test #2
=============== =======
1) Click on the row where ID = 1
2) Click "Add Row" button
3) Click "Remove Binding"
4) Click "Add Binding"
5) Click on the cell ID = 2 Number = 4
6) Change the number from 4 to 5
7) Move off the row (i.e. hit the down arrow key)
8) Notice there are 2 rows with ID = 2 now
2, 5, 6
2, 4, 6

=============== ===========

using System;
using System.Data;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;

namespace Controls
{
/// <summary>
/// Summary description for TestDataGrid.
/// </summary>
public class TestDataGrid : System.Windows. Forms.Form
{
private int idCounter = 100;

#region Unimportant Window stuff

private System.Windows. Forms.DataGrid theGrid;
private System.Windows. Forms.Button addButton;
private System.Data.Dat aSet myDataSet;
private System.Data.Dat aTable rateTable;
private System.Data.Dat aColumn dataColumn1;
private System.Data.Dat aColumn dataColumn2;
private System.Data.Dat aColumn dataColumn3;
private System.Windows. Forms.Button removeBinding;
private System.Windows. Forms.Button addBinding;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components =
null;

public TestDataGrid()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after
InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.theGrid = new
System.Windows. Forms.DataGrid( );
this.myDataSet = new System.Data.Dat aSet();
this.rateTable = new System.Data.Dat aTable();
this.dataColumn 1 = new
System.Data.Dat aColumn();
this.dataColumn 2 = new
System.Data.Dat aColumn();
this.dataColumn 3 = new
System.Data.Dat aColumn();
this.addButton = new
System.Windows. Forms.Button();
this.removeBind ing = new
System.Windows. Forms.Button();
this.addBinding = new
System.Windows. Forms.Button();

((System.Compon entModel.ISuppo rtInitialize)(t his.theGrid)).B eginInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.myDataSet)) .BeginInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.rateTable)) .BeginInit();
this.SuspendLay out();
//
// theGrid
//
this.theGrid.An chor =
((System.Window s.Forms.AnchorS tyles)((((Syste m.Windows.Forms .AnchorStyles.T op
| System.Windows. Forms.AnchorSty les.Bottom)
|
System.Windows. Forms.AnchorSty les.Left)
|
System.Windows. Forms.AnchorSty les.Right)));
this.theGrid.Da taMember = "RateTable" ;
this.theGrid.Da taSource = this.myDataSet;
this.theGrid.He aderForeColor =
System.Drawing. SystemColors.Co ntrolText;
this.theGrid.Lo cation = new
System.Drawing. Point(8, 40);
this.theGrid.Na me = "theGrid";
this.theGrid.Si ze = new
System.Drawing. Size(368, 184);
this.theGrid.Ta bIndex = 0;
//
// myDataSet
//
this.myDataSet. DataSetName = "NewDataSet ";
this.myDataSet. Locale = new
System.Globaliz ation.CultureIn fo("en-US");
this.myDataSet. Tables.AddRange (new
System.Data.Dat aTable[] {

this.rateTable} );
//
// rateTable
//
this.rateTable. Columns.AddRang e(new
System.Data.Dat aColumn[] {

this.dataColumn 1,

this.dataColumn 2,

this.dataColumn 3});
this.rateTable. TableName = "RateTable" ;
//
// dataColumn1
//
this.dataColumn 1.ColumnName = "ID";
this.dataColumn 1.DataType = typeof(int);
//
// dataColumn2
//
this.dataColumn 2.ColumnName = "Number";
this.dataColumn 2.DataType = typeof(int);
//
// dataColumn3
//
this.dataColumn 3.ColumnName = "Price";
this.dataColumn 3.DataType = typeof(int);
//
// addButton
//
this.addButton. Anchor =
((System.Window s.Forms.AnchorS tyles)((System. Windows.Forms.A nchorStyles.Bot tom
| System.Windows. Forms.AnchorSty les.Left)));
this.addButton. Location = new
System.Drawing. Point(16, 256);
this.addButton. Name = "addButton" ;
this.addButton. TabIndex = 1;
this.addButton. Text = "Add Row";
this.addButton. Click += new
System.EventHan dler(this.addBu tton_Click);
//
// removeBinding
//
this.removeBind ing.Anchor =
((System.Window s.Forms.AnchorS tyles)((System. Windows.Forms.A nchorStyles.Bot tom
| System.Windows. Forms.AnchorSty les.Left)));
this.removeBind ing.Location = new
System.Drawing. Point(136, 256);
this.removeBind ing.Name = "removeBinding" ;
this.removeBind ing.Size = new
System.Drawing. Size(104, 23);
this.removeBind ing.TabIndex = 3;
this.removeBind ing.Text = "Remove Binding";
this.removeBind ing.Click += new
System.EventHan dler(this.remov eBinding_Click) ;
//
// addBinding
//
this.addBinding .Anchor =
((System.Window s.Forms.AnchorS tyles)((System. Windows.Forms.A nchorStyles.Bot tom
| System.Windows. Forms.AnchorSty les.Left)));
this.addBinding .Location = new
System.Drawing. Point(288, 256);
this.addBinding .Name = "addBinding ";
this.addBinding .Size = new
System.Drawing. Size(104, 23);
this.addBinding .TabIndex = 4;
this.addBinding .Text = "Add Binding";
this.addBinding .Click += new
System.EventHan dler(this.addBi nding_Click);
//
// TestDataGrid
//
this.AutoScaleB aseSize = new
System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(400,
293);
this.Controls.A dd(this.addBind ing);
this.Controls.A dd(this.removeB inding);
this.Controls.A dd(this.addButt on);
this.Controls.A dd(this.theGrid );
this.Name = "TestDataGr id";
this.StartPosit ion =
System.Windows. Forms.FormStart Position.Center Screen;
this.Text = "TestDataGr id";
this.Load += new
System.EventHan dler(this.TestD ataGrid_Load);

((System.Compon entModel.ISuppo rtInitialize)(t his.theGrid)).E ndInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.myDataSet)) .EndInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.rateTable)) .EndInit();
this.ResumeLayo ut(false);

}
#endregion

#endregion

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void addButton_Click (object sender,
System.EventArg s e)
{
Random random = new
Random(idCounte r);
DataRow row = rateTable.NewRo w();
int position = theGrid.Current RowIndex + 1;

row[0] = idCounter++;
row[1] = (int)( random.NextDoub le() * 100 );
row[2] = (int)( random.NextDoub le() * 10 );

rateTable.Rows. InsertAt( row, position );
rateTable.Accep tChanges();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void removeBinding_C lick(object sender,
System.EventArg s e)
{
this.theGrid.Da taSource = null;
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void addBinding_Clic k(object sender,
System.EventArg s e)
{
this.theGrid.Da taMember = "RateTable" ;
this.theGrid.Da taSource = this.myDataSet;
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TestDataGrid_Lo ad(object sender,
System.EventArg s e)
{
int numRows = 5;
DataRow row;

for (int i = 0; i < numRows; i++)
{
row = rateTable.NewRo w();
row[0] = i * 1;
row[1] = i * 2;
row[2] = i * 3;

rateTable.Rows. Add( row );
}
}
}
}
Aug 15 '05 #1
5 2938
From your description (I haven't run the code or looked at it closely), the
issue is that even if the new row is added to the middle of the list, it
always shows up in the end.

This is a known bug with the DataView (when you bind to a DataTable, you are
really binding to its DefaultView property which is a DataView). I believe
it should be resolved with the 2.0 framework.

"Dave" <Da**@discussio ns.microsoft.co m> wrote in message
news:38******** *************** ***********@mic rosoft.com...
I tried posting this in the WinForm forum and got no hits so I am
trying it here.

After inserting a new data row to a DataTable that is bound to a
datagrid, I am unable to change data in a row that is after the newly
added row without getting bizarre results.

I have added the full code for the test below. Create a project drop
in the code and run. There is nothing crazy about the code. I used
the designer to add the dataset and to do the binding.

Any help would be appreciated.

Cheers,
Dave
Test #1
=============== =======
1) Click on the row where ID = 1
2) Click "Add Row" button
3) Click on the cell ID = 2 Number = 4
4) Change the number from 4 to 5
5) Move off the row (i.e. hit the down arrow key)
6) Notice there are 2 rows with ID = 2 now
2, 5, 6
2, 4, 6
Test #2
=============== =======
1) Click on the row where ID = 1
2) Click "Add Row" button
3) Click "Remove Binding"
4) Click "Add Binding"
5) Click on the cell ID = 2 Number = 4
6) Change the number from 4 to 5
7) Move off the row (i.e. hit the down arrow key)
8) Notice there are 2 rows with ID = 2 now
2, 5, 6
2, 4, 6

=============== ===========

using System;
using System.Data;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;

namespace Controls
{
/// <summary>
/// Summary description for TestDataGrid.
/// </summary>
public class TestDataGrid : System.Windows. Forms.Form
{
private int idCounter = 100;

#region Unimportant Window stuff

private System.Windows. Forms.DataGrid theGrid;
private System.Windows. Forms.Button addButton;
private System.Data.Dat aSet myDataSet;
private System.Data.Dat aTable rateTable;
private System.Data.Dat aColumn dataColumn1;
private System.Data.Dat aColumn dataColumn2;
private System.Data.Dat aColumn dataColumn3;
private System.Windows. Forms.Button removeBinding;
private System.Windows. Forms.Button addBinding;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components =
null;

public TestDataGrid()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after
InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.theGrid = new
System.Windows. Forms.DataGrid( );
this.myDataSet = new System.Data.Dat aSet();
this.rateTable = new System.Data.Dat aTable();
this.dataColumn 1 = new
System.Data.Dat aColumn();
this.dataColumn 2 = new
System.Data.Dat aColumn();
this.dataColumn 3 = new
System.Data.Dat aColumn();
this.addButton = new
System.Windows. Forms.Button();
this.removeBind ing = new
System.Windows. Forms.Button();
this.addBinding = new
System.Windows. Forms.Button();

((System.Compon entModel.ISuppo rtInitialize)(t his.theGrid)).B eginInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.myDataSet)) .BeginInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.rateTable)) .BeginInit();
this.SuspendLay out();
//
// theGrid
//
this.theGrid.An chor =
((System.Window s.Forms.AnchorS tyles)((((Syste m.Windows.Forms .AnchorStyles.T op
| System.Windows. Forms.AnchorSty les.Bottom)
|
System.Windows. Forms.AnchorSty les.Left)
|
System.Windows. Forms.AnchorSty les.Right)));
this.theGrid.Da taMember = "RateTable" ;
this.theGrid.Da taSource = this.myDataSet;
this.theGrid.He aderForeColor =
System.Drawing. SystemColors.Co ntrolText;
this.theGrid.Lo cation = new
System.Drawing. Point(8, 40);
this.theGrid.Na me = "theGrid";
this.theGrid.Si ze = new
System.Drawing. Size(368, 184);
this.theGrid.Ta bIndex = 0;
//
// myDataSet
//
this.myDataSet. DataSetName = "NewDataSet ";
this.myDataSet. Locale = new
System.Globaliz ation.CultureIn fo("en-US");
this.myDataSet. Tables.AddRange (new
System.Data.Dat aTable[] {

this.rateTable} );
//
// rateTable
//
this.rateTable. Columns.AddRang e(new
System.Data.Dat aColumn[] {

this.dataColumn 1,

this.dataColumn 2,

this.dataColumn 3});
this.rateTable. TableName = "RateTable" ;
//
// dataColumn1
//
this.dataColumn 1.ColumnName = "ID";
this.dataColumn 1.DataType = typeof(int);
//
// dataColumn2
//
this.dataColumn 2.ColumnName = "Number";
this.dataColumn 2.DataType = typeof(int);
//
// dataColumn3
//
this.dataColumn 3.ColumnName = "Price";
this.dataColumn 3.DataType = typeof(int);
//
// addButton
//
this.addButton. Anchor =
((System.Window s.Forms.AnchorS tyles)((System. Windows.Forms.A nchorStyles.Bot tom
| System.Windows. Forms.AnchorSty les.Left)));
this.addButton. Location = new
System.Drawing. Point(16, 256);
this.addButton. Name = "addButton" ;
this.addButton. TabIndex = 1;
this.addButton. Text = "Add Row";
this.addButton. Click += new
System.EventHan dler(this.addBu tton_Click);
//
// removeBinding
//
this.removeBind ing.Anchor =
((System.Window s.Forms.AnchorS tyles)((System. Windows.Forms.A nchorStyles.Bot tom
| System.Windows. Forms.AnchorSty les.Left)));
this.removeBind ing.Location = new
System.Drawing. Point(136, 256);
this.removeBind ing.Name = "removeBinding" ;
this.removeBind ing.Size = new
System.Drawing. Size(104, 23);
this.removeBind ing.TabIndex = 3;
this.removeBind ing.Text = "Remove Binding";
this.removeBind ing.Click += new
System.EventHan dler(this.remov eBinding_Click) ;
//
// addBinding
//
this.addBinding .Anchor =
((System.Window s.Forms.AnchorS tyles)((System. Windows.Forms.A nchorStyles.Bot tom
| System.Windows. Forms.AnchorSty les.Left)));
this.addBinding .Location = new
System.Drawing. Point(288, 256);
this.addBinding .Name = "addBinding ";
this.addBinding .Size = new
System.Drawing. Size(104, 23);
this.addBinding .TabIndex = 4;
this.addBinding .Text = "Add Binding";
this.addBinding .Click += new
System.EventHan dler(this.addBi nding_Click);
//
// TestDataGrid
//
this.AutoScaleB aseSize = new
System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(400,
293);
this.Controls.A dd(this.addBind ing);
this.Controls.A dd(this.removeB inding);
this.Controls.A dd(this.addButt on);
this.Controls.A dd(this.theGrid );
this.Name = "TestDataGr id";
this.StartPosit ion =
System.Windows. Forms.FormStart Position.Center Screen;
this.Text = "TestDataGr id";
this.Load += new
System.EventHan dler(this.TestD ataGrid_Load);

((System.Compon entModel.ISuppo rtInitialize)(t his.theGrid)).E ndInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.myDataSet)) .EndInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.rateTable)) .EndInit();
this.ResumeLayo ut(false);

}
#endregion

#endregion

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void addButton_Click (object sender,
System.EventArg s e)
{
Random random = new
Random(idCounte r);
DataRow row = rateTable.NewRo w();
int position = theGrid.Current RowIndex + 1;

row[0] = idCounter++;
row[1] = (int)( random.NextDoub le() * 100 );
row[2] = (int)( random.NextDoub le() * 10 );

rateTable.Rows. InsertAt( row, position );
rateTable.Accep tChanges();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void removeBinding_C lick(object sender,
System.EventArg s e)
{
this.theGrid.Da taSource = null;
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void addBinding_Clic k(object sender,
System.EventArg s e)
{
this.theGrid.Da taMember = "RateTable" ;
this.theGrid.Da taSource = this.myDataSet;
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TestDataGrid_Lo ad(object sender,
System.EventArg s e)
{
int numRows = 5;
DataRow row;

for (int i = 0; i < numRows; i++)
{
row = rateTable.NewRo w();
row[0] = i * 1;
row[1] = i * 2;
row[2] = i * 3;

rateTable.Rows. Add( row );
}
}
}
}

Aug 15 '05 #2
Dave,

In my opinion do you show us to much code.
The change that you get an answer on this is probably very small.

Try to give the essential part of your problem

In addition, because that you are using C# code you have probably even a
better change on an answer in the newsgroup

microsoft.publi c.dotnet.langua ges.csharp

Which does not mean that you cannot get an answer here, however take my
advice make it in a way that we can understand the problem quick.

By instance is it for your problem really not important how the datagrid is
anchored on the form.

I hope this helps,

Cor
Aug 15 '05 #3
Marina,
This is a known bug with the DataView (when you bind to a DataTable,


Do you mean DataGrid, in that case I know it?

Cor
Aug 15 '05 #4
90% of the code is generated by dragging controls on the form.
From addButton_Click down is code that I manually typed, some
20 lines of code altogether.

To the best of my ability there is no possible way of providing a
demo that is smaller.
The barest way to describe the problem is I have
1) Dragged a DataGrid, DataSet, and 3 buttons onto the form
2) Added columns to the DataSet
3) Bound DataSet to DataGrid
4) Double clicked each button "Add Row" "Remove Binding" "Add Binding"
and added appropriate 5-8 lines of code
5) Added default data to Form Load
6) Start App
7) Position cursor on row 1
8) Click "Add Row" Button
9) Modify row after new row and it BLOWS UP

Cheers,
Dave

Cheers,
Dave

"Cor Ligthert [MVP]" wrote:
Dave,

In my opinion do you show us to much code.
The change that you get an answer on this is probably very small.

Try to give the essential part of your problem

In addition, because that you are using C# code you have probably even a
better change on an answer in the newsgroup

microsoft.publi c.dotnet.langua ges.csharp

Which does not mean that you cannot get an answer here, however take my
advice make it in a way that we can understand the problem quick.

By instance is it for your problem really not important how the datagrid is
anchored on the form.

I hope this helps,

Cor

Aug 15 '05 #5

You said, "From your description (I haven't run the code or looked at it
closely), the issue is that even if the new row is added to the middle of the
list, it always shows up in the end."

I say: NO. Either a CurrencyManger. Refresh or AcceptChanges will put it in
the correct position. This is not the problem. The problem is after I do
either of these methods above and try to modify a row AFTER the new row that
was added, I get null and duplicat rows and then the app crashes and burns.

Cheers,
Dave

"Marina" wrote:
From your description (I haven't run the code or looked at it closely), the
issue is that even if the new row is added to the middle of the list, it
always shows up in the end.

This is a known bug with the DataView (when you bind to a DataTable, you are
really binding to its DefaultView property which is a DataView). I believe
it should be resolved with the 2.0 framework.

"Dave" <Da**@discussio ns.microsoft.co m> wrote in message
news:38******** *************** ***********@mic rosoft.com...
I tried posting this in the WinForm forum and got no hits so I am
trying it here.

After inserting a new data row to a DataTable that is bound to a
datagrid, I am unable to change data in a row that is after the newly
added row without getting bizarre results.

I have added the full code for the test below. Create a project drop
in the code and run. There is nothing crazy about the code. I used
the designer to add the dataset and to do the binding.

Any help would be appreciated.

Cheers,
Dave
Test #1
=============== =======
1) Click on the row where ID = 1
2) Click "Add Row" button
3) Click on the cell ID = 2 Number = 4
4) Change the number from 4 to 5
5) Move off the row (i.e. hit the down arrow key)
6) Notice there are 2 rows with ID = 2 now
2, 5, 6
2, 4, 6
Test #2
=============== =======
1) Click on the row where ID = 1
2) Click "Add Row" button
3) Click "Remove Binding"
4) Click "Add Binding"
5) Click on the cell ID = 2 Number = 4
6) Change the number from 4 to 5
7) Move off the row (i.e. hit the down arrow key)
8) Notice there are 2 rows with ID = 2 now
2, 5, 6
2, 4, 6

=============== ===========

using System;
using System.Data;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;

namespace Controls
{
/// <summary>
/// Summary description for TestDataGrid.
/// </summary>
public class TestDataGrid : System.Windows. Forms.Form
{
private int idCounter = 100;

#region Unimportant Window stuff

private System.Windows. Forms.DataGrid theGrid;
private System.Windows. Forms.Button addButton;
private System.Data.Dat aSet myDataSet;
private System.Data.Dat aTable rateTable;
private System.Data.Dat aColumn dataColumn1;
private System.Data.Dat aColumn dataColumn2;
private System.Data.Dat aColumn dataColumn3;
private System.Windows. Forms.Button removeBinding;
private System.Windows. Forms.Button addBinding;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components =
null;

public TestDataGrid()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after
InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.theGrid = new
System.Windows. Forms.DataGrid( );
this.myDataSet = new System.Data.Dat aSet();
this.rateTable = new System.Data.Dat aTable();
this.dataColumn 1 = new
System.Data.Dat aColumn();
this.dataColumn 2 = new
System.Data.Dat aColumn();
this.dataColumn 3 = new
System.Data.Dat aColumn();
this.addButton = new
System.Windows. Forms.Button();
this.removeBind ing = new
System.Windows. Forms.Button();
this.addBinding = new
System.Windows. Forms.Button();

((System.Compon entModel.ISuppo rtInitialize)(t his.theGrid)).B eginInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.myDataSet)) .BeginInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.rateTable)) .BeginInit();
this.SuspendLay out();
//
// theGrid
//
this.theGrid.An chor =
((System.Window s.Forms.AnchorS tyles)((((Syste m.Windows.Forms .AnchorStyles.T op
| System.Windows. Forms.AnchorSty les.Bottom)
|
System.Windows. Forms.AnchorSty les.Left)
|
System.Windows. Forms.AnchorSty les.Right)));
this.theGrid.Da taMember = "RateTable" ;
this.theGrid.Da taSource = this.myDataSet;
this.theGrid.He aderForeColor =
System.Drawing. SystemColors.Co ntrolText;
this.theGrid.Lo cation = new
System.Drawing. Point(8, 40);
this.theGrid.Na me = "theGrid";
this.theGrid.Si ze = new
System.Drawing. Size(368, 184);
this.theGrid.Ta bIndex = 0;
//
// myDataSet
//
this.myDataSet. DataSetName = "NewDataSet ";
this.myDataSet. Locale = new
System.Globaliz ation.CultureIn fo("en-US");
this.myDataSet. Tables.AddRange (new
System.Data.Dat aTable[] {

this.rateTable} );
//
// rateTable
//
this.rateTable. Columns.AddRang e(new
System.Data.Dat aColumn[] {

this.dataColumn 1,

this.dataColumn 2,

this.dataColumn 3});
this.rateTable. TableName = "RateTable" ;
//
// dataColumn1
//
this.dataColumn 1.ColumnName = "ID";
this.dataColumn 1.DataType = typeof(int);
//
// dataColumn2
//
this.dataColumn 2.ColumnName = "Number";
this.dataColumn 2.DataType = typeof(int);
//
// dataColumn3
//
this.dataColumn 3.ColumnName = "Price";
this.dataColumn 3.DataType = typeof(int);
//
// addButton
//
this.addButton. Anchor =
((System.Window s.Forms.AnchorS tyles)((System. Windows.Forms.A nchorStyles.Bot tom
| System.Windows. Forms.AnchorSty les.Left)));
this.addButton. Location = new
System.Drawing. Point(16, 256);
this.addButton. Name = "addButton" ;
this.addButton. TabIndex = 1;
this.addButton. Text = "Add Row";
this.addButton. Click += new
System.EventHan dler(this.addBu tton_Click);
//
// removeBinding
//
this.removeBind ing.Anchor =
((System.Window s.Forms.AnchorS tyles)((System. Windows.Forms.A nchorStyles.Bot tom
| System.Windows. Forms.AnchorSty les.Left)));
this.removeBind ing.Location = new
System.Drawing. Point(136, 256);
this.removeBind ing.Name = "removeBinding" ;
this.removeBind ing.Size = new
System.Drawing. Size(104, 23);
this.removeBind ing.TabIndex = 3;
this.removeBind ing.Text = "Remove Binding";
this.removeBind ing.Click += new
System.EventHan dler(this.remov eBinding_Click) ;
//
// addBinding
//
this.addBinding .Anchor =
((System.Window s.Forms.AnchorS tyles)((System. Windows.Forms.A nchorStyles.Bot tom
| System.Windows. Forms.AnchorSty les.Left)));
this.addBinding .Location = new
System.Drawing. Point(288, 256);
this.addBinding .Name = "addBinding ";
this.addBinding .Size = new
System.Drawing. Size(104, 23);
this.addBinding .TabIndex = 4;
this.addBinding .Text = "Add Binding";
this.addBinding .Click += new
System.EventHan dler(this.addBi nding_Click);
//
// TestDataGrid
//
this.AutoScaleB aseSize = new
System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(400,
293);
this.Controls.A dd(this.addBind ing);
this.Controls.A dd(this.removeB inding);
this.Controls.A dd(this.addButt on);
this.Controls.A dd(this.theGrid );
this.Name = "TestDataGr id";
this.StartPosit ion =
System.Windows. Forms.FormStart Position.Center Screen;
this.Text = "TestDataGr id";
this.Load += new
System.EventHan dler(this.TestD ataGrid_Load);

((System.Compon entModel.ISuppo rtInitialize)(t his.theGrid)).E ndInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.myDataSet)) .EndInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.rateTable)) .EndInit();
this.ResumeLayo ut(false);

}
#endregion

#endregion

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void addButton_Click (object sender,
System.EventArg s e)
{
Random random = new
Random(idCounte r);
DataRow row = rateTable.NewRo w();
int position = theGrid.Current RowIndex + 1;

row[0] = idCounter++;
row[1] = (int)( random.NextDoub le() * 100 );
row[2] = (int)( random.NextDoub le() * 10 );

rateTable.Rows. InsertAt( row, position );
rateTable.Accep tChanges();
}

Aug 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1964
by: Frosty | last post by:
Hi I am using the VS xsd designer to create a strongly typed dataset. The dataset is apparently successfully created, with no warnings or errors given. Is it not then to be expected that this dataset then should reflect all the details put into the xsd? Somewhere down the line there is not a 1:1 relationship. Be it that .NET is so tightly...
3
2530
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called "Resource" with the following structure : Resource{,en,fr,es} Yes.. these are the only languages supported actually. A couple of rows in that table would...
0
367
by: David | last post by:
Hello. I have some little problem with DataSet and I hope somebody will help me. So what's my problem: I have DataSet with some table in it lets say table name is "Suppliers", I have DataGrid to show the records from this DataSet and toolbar fornavigating and editing rows in DataSet. I'm using another form for editing data and the manualy...
0
3479
by: Dave | last post by:
Tried posting in the Winform Forum without much luck, so posting here... After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is after the newly added row without getting bizarre results. I have added the full code for the test below. Create a project drop in the code and...
2
4809
by: Alpha | last post by:
Hi, I have a window based program. One of the form has several textboxes and a datagrid. The textboxes are bind to the same dataset table as the datagrid and the text changes to reflect different row selected in the datagrid. I want to save the changes that user make in the textboxes when they select a different row in the datagrid. I...
2
3374
by: John Holmes | last post by:
I have a web interface where the user types in ID's one at a time. After an ID is typed in, a button is clicked and the button click event has code that does a query and returns a data reader and then appends the data to a dataset that is built in the Page_Load code in the if(!isPostBack) block. When I try to add a row in the button click...
12
1674
by: Bishoy George | last post by:
I have a dataset called ds1 filled with 2 tables Employees and Customers from Northwind database. I have dropdownList called ddLastName with the following properties: ddLastName.DataSource = ds1; ddLastName.DataMember = "Employees"; ddLastName.DataTextField = "LastName"; ddLastName.DataBind(); ddLastName.Items.Insert(0,"Select:");
10
5634
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1) DsStudentCourse1.AcceptChanges() i'm also wondering because w/ out AcceptChanges the data is still save into the database and it is now faster.
0
1111
by: paulhux174 | last post by:
Hi, I've a dataGrid set up (the standard msdn example) with a SqlDataAdapter, and DataSet. The problem is that after inserting a new row using the LinkButton1_Click() (code below) then edit the values I then try to update the values using "DataGrid1_UpdateCommand()" The FindByApplID does't find the row. It looks like the...
4
1268
by: Abby | last post by:
Hi all, I have a datagrid which i am using for updating the data to the database. It works fine for single row data however when i have multiple rows(records) associated with the same criteria(billno) it updates both the rows with the values for the row i updated. I thought of reading both the rows into a dataset and update that to the...
0
7457
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7802
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7410
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7746
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5962
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5320
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3438
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1869
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.