Add new record using bound controls on windows form

  • Thread starter Thread starter Paul Edwards
  • Start date Start date
P

Paul Edwards

I am writing an application in c# that connects to a SQL
server database. Following examples etc I can use bound
controls and with the position property go to a row and
edit it and save changes back to database. The problem is
I can't find how to set the position of the form to a new
row. If I just add a blank row to the datatable and then
try to go to it only works if all columns are nillable,
however this then leaves room for errors or I have to put
default values in columns that I don't want to have them.

Is there any way to point a bound form to a new row?

Thanks in advance
Paul
 
Hi Paul,

What if you add a row with all columns having their default values

table.Rows.Add(new object[] {-1, "John", "Doe", "WA", "90876"});

And then set the CurrencyManager's position to the index of that row?
 
Dmitriy

Thanks for your suggestion but I have tried it and it
looks wrong to users to have a default name of John Doe on
the form, and combo boxes showing wrong values. Is there a
way to start it with blank values for all fields?

Paul
-----Original Message-----
Hi Paul,

What if you add a row with all columns having their default values

table.Rows.Add(new object[] {-
1, "John", "Doe", "WA", "90876"});
And then set the CurrencyManager's position to the index of that row?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

I am writing an application in c# that connects to a SQL
server database. Following examples etc I can use bound
controls and with the position property go to a row and
edit it and save changes back to database. The problem is
I can't find how to set the position of the form to a new
row. If I just add a blank row to the datatable and then
try to go to it only works if all columns are nillable,
however this then leaves room for errors or I have to put
default values in columns that I don't want to have them.

Is there any way to point a bound form to a new row?

Thanks in advance
Paul

.
 
Back
Top