How to set values in datagrid?

M

Michael

Hi all,
I am using Datagrid control in VB.Net 2003.
Now I have a problem like this,
when user changed the value in a cell in datagrid, I want all the
values in the same column below the current row changed to the new
value.
How can I do this?
I use currentcellchaged event like below:

Private Sub myGRID_CurrentCellChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles myGRID.CurrentCellChanged
''''Get total row count
Dim i as Integer
Dim NewValue as Integer
NewValue=CInt(myGRID.Item(myGRID.CurrentRowIndex,
ColumnNumber))
i = myGRID.BindingContext(Me.ALLOCATIONS_GRID.DataSource,
myGRID.DataMember).Count()
If (myGRID.CurrentRowIndex + 1) < i Then
myGRID.Item(myGRID.CurrentRowIndex + 1, ColumnNumber) =
NewValue
End If
End Sub


Can anybody advise on this?
I always get "ListManager's position must equal to rownum" exception.
Thanks.


Regars,
Michael
 
C

Cor Ligthert[MVP]

Michael,


A datagrid is a data control.

To access it you can the most simple use the object in the datasource (a
dataview or a datatable).

That is simple to do with a for each or a for index loop.


Cor
 
M

Michael

Michael,

A datagrid is a data control.

To access it you can the most simple use the object in the datasource (a
dataview or a datatable).

That is simple to do with a for each or a for index loop.

Cor

Thanks Cor,
Would you please tell me more if I do this in the datatable?
What event should I put the code in?
Thanks.

Regards,
Michael
 
C

Cor Ligthert[MVP]

Michael,

Assuming that your datasource is a datatable.

\\\
dim dt as DataTable = DirectCast(TheDataGrid.DataSource, DataGrid)
for each dr as DataRow in dt.Rows
dr.Item("TheField") = "Michael"
next
///

Cor
 
M

Michael

Sorry,> \\\

dim dt as DataTable = DirectCast(TheDataGrid.DataSource, DataTable)
///

Hi Cor,
thanks for your help.
But what I want is like this,
I have a datatable, and use a datagrid to display it.
users want to modify the value in datagrid,
let's say he changed the value in row 1, column 1,
now I have to changes all the values in coumn 1 for the other rows.
I guess I should make this change in some datagrid event, because this
should be invoked automatically.
That is, after users modify the value in a cell, datagrid will
automatically change the value in below rows.
Hope this make sense.
Thanks.

Regards,
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top