Hi all,

I have a very simple question: how to set default values in a new table row?

1. DataTable.RowChanged does not work if I have gui controls bound to the
table, because it fires after the new record is accepted.
2. DataColumn.DefaultValue does not work either - what if I want to store
the exact row-creation time?
3. CurrencyManager.PositionChanged does not work either - what if I don't
have controls bound to to table.

So, where is the DataTable.OnNewRow event ???

Regards
radi

Values in a new datatable row by Javed

Javed
Wed Sep 17 11:11:55 CDT 2003

Usually you construct the new Row first and then add it
to the DataTable. For example, to add a row to the
Person Table you could create a function:

Public Function PersonRow(ByVal dt As DataTable)
Dim aRow As DataRow = dt.NewRow
aRow("lastname") = ""
aRow("firstname") = ""
Return aRow
End Function

and then if Person is a Table in your Dataset, ds, you
could write:

ds.Tables("Person").Rows.Add(PersonRow(ds.Tables
("Person")))

You write this code perhaps in the Click event of a
button that the user clicks to add a new row - or
something similar. Only after the Row is added can you
talk of changing the position to it.


>-----Original Message-----
>Hi all,
>
>I have a very simple question: how to set default values
in a new table row?
>
>1. DataTable.RowChanged does not work if I have gui
controls bound to the
>table, because it fires after the new record is accepted.
>2. DataColumn.DefaultValue does not work either - what
if I want to store
>the exact row-creation time?
>3. CurrencyManager.PositionChanged does not work either -
what if I don't
>have controls bound to to table.
>
>So, where is the DataTable.OnNewRow event ???
>
>Regards
>radi
>
>
>.
>

Values in a new datatable row by Ravikanth[MVP]

Ravikanth[MVP]
Wed Sep 17 11:35:52 CDT 2003

Hi

Please look into the following article.
http://www.dotnetbips.com/displayarticle.aspx?id=125

HTH
Ravikanth[MVP]


>-----Original Message-----
>Hi all,
>
>I have a very simple question: how to set default values
in a new table row?
>
>1. DataTable.RowChanged does not work if I have gui
controls bound to the
>table, because it fires after the new record is accepted.
>2. DataColumn.DefaultValue does not work either - what
if I want to store
>the exact row-creation time?
>3. CurrencyManager.PositionChanged does not work either -
what if I don't
>have controls bound to to table.
>
>So, where is the DataTable.OnNewRow event ???
>
>Regards
>radi
>
>
>.
>

Re: Values in a new datatable row by Radostin

Radostin
Wed Sep 17 12:57:52 CDT 2003

You are right - but your solution works only if I create the new row
programmatically. What if the user inserts a new row through a datagrid ?

"Javed" <busy@sulfurmines.com> wrote in message
news:095601c37d36$6a3092a0$a001280a@phx.gbl...
> Usually you construct the new Row first and then add it
> to the DataTable. For example, to add a row to the
> Person Table you could create a function:
>

radi



Values in a new datatable row by JT

JT
Wed Sep 17 13:12:30 CDT 2003

Hi,
If you are using a non-typed datatable to store your new
row, you could code:

mydTable.Columns("myColumnName").DefaultValue = whatever

If you are using a strongly typed datatable, you could do
the above, OR, you could open the .xsd and click on the
datatable attribute you wish to default. In the
properties window, you will see 'default' under the Misc
properties.
Hope this helps.
JT
>-----Original Message-----
>Hi all,
>
>I have a very simple question: how to set default values
in a new table row?
>
>1. DataTable.RowChanged does not work if I have gui
controls bound to the
>table, because it fires after the new record is accepted.
>2. DataColumn.DefaultValue does not work either - what if
I want to store
>the exact row-creation time?
>3. CurrencyManager.PositionChanged does not work either -
what if I don't
>have controls bound to to table.
>
>So, where is the DataTable.OnNewRow event ???
>
>Regards
>radi
>
>
>.
>

Re: Values in a new datatable row by Radostin

Radostin
Wed Sep 17 13:21:26 CDT 2003

Hi,

Thank you very much for your effort.
Have you actually read my question or you just looked at the subject and
posted some random link?

I will explain again: I have a System.Data.DataTable object which may or may
not be bound to some user controls. I cannot find a way to set some default
values in a new datatable row because I cannot find an event, that fires
when a new row is created.

"Ravikanth[MVP]" <dvravikanth@hotmail.com> wrote in message
news:032001c37d39$c25c69b0$a101280a@phx.gbl...
> Hi
>
> Please look into the following article.
> http://www.dotnetbips.com/displayarticle.aspx?id=125
>
> HTH
> Ravikanth[MVP]



Re: Values in a new datatable row by Radostin

Radostin
Thu Sep 18 08:17:21 CDT 2003

Hi,
Thanks for your answer.

Please read again my question and take a look at Scenario 2.

radi


> If you are using a non-typed datatable to store your new
> row, you could code:
>
> mydTable.Columns("myColumnName").DefaultValue = whatever
>



Re: Values in a new datatable row by JT

JT
Thu Sep 18 08:30:14 CDT 2003

Radi,
Some advice - Never preface a question with 'very simple'
and then attach three parts to it. Anyway, with regards
to scenario 2, could you not capture the time the row was
created in a datetime column in your datatable by setting
its value to Now at row creation time?
JT
>-----Original Message-----
>Hi,
>Thanks for your answer.
>
>Please read again my question and take a look at Scenario
2.
>
>radi
>
>
>> If you are using a non-typed datatable to store your new
>> row, you could code:
>>
>> mydTable.Columns("myColumnName").DefaultValue =
whatever
>>
>
>
>.
>

Re: Values in a new datatable row by Radostin

Radostin
Mon Sep 22 08:31:44 CDT 2003

Hi,

> Some advice - Never preface a question with 'very simple'
> and then attach three parts to it.

Well, the question is indeed very simple. The answer, if any, is not.

>Anyway, with regards
> to scenario 2, could you not capture the time the row was
> created in a datetime column in your datatable by setting
> its value to Now at row creation time?

I can do that. But it seems you didn't understand the problem - there is no
uniform way(event) to initialize a new DataRow in a DataTable. All of the
suggestions are bound to a particular proposition.

Anyway, thank you very much for your efforts.

radi