DataGrid still...

  • Thread starter Thread starter pcPirate
  • Start date Start date
P

pcPirate

Hi,
I've followed some advice through this forum in which I would change the
dataset value in order to change the particular cell value in datagrid via
coding.

What I'm doing now is that, if I change the first column, the second column
in the same row would display the same input as the first's. The way I did
is to take the row no. of the column edited and update the dataset in the
same row, second column. However, the datagrid actually allowed sorting and
once the it is sorted, the row to be updated in dataset would be incorrect.

Question is:
i) Is there any better way to update the dataset?

Pls advise and thanks in advance.
pcPirate
 
Hi,

There's a thread in the windowsforms.controls newsgroup titled
"How to find data in sorted DataGrid control". I have given an example of
accessing the appropriate DataRow there.
 
Dmitriy,
Thanks a lot for the reply,
My database table to be displayed in the datagrid has a lot of fields and it
would be quite unwise to use the dataTable (which is needed in your example)
Is there anyway still to work around with dataset? All I ask is just to get
the exact row of the dataset.

Pls. advise and thanks in advance.
pcPirate


Dmitriy Lapshin said:
Hi,

There's a thread in the windowsforms.controls newsgroup titled
"How to find data in sorted DataGrid control". I have given an example of
accessing the appropriate DataRow there.

--
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

pcPirate said:
Hi,
I've followed some advice through this forum in which I would change the
dataset value in order to change the particular cell value in datagrid via
coding.

What I'm doing now is that, if I change the first column, the second column
in the same row would display the same input as the first's. The way I did
is to take the row no. of the column edited and update the dataset in the
same row, second column. However, the datagrid actually allowed sorting and
once the it is sorted, the row to be updated in dataset would be incorrect.

Question is:
i) Is there any better way to update the dataset?

Pls advise and thanks in advance.
pcPirate
 
In some cases I use a primary key field in my grid to search against the
DataTable. I apply a TableStyle to prevent the key from being displayed.

int key = (int)productGrid[productGrid.CurrentRowIndex, 0];
DataRow dr = ((DataTable)Grid.DataSource).Rows.Find(key);

It's never failed.

If you are using DataBinding and you don't have a PK for the table, you can
designate one or more columns at runtime. It will enforce that they are
unique values. I'm not sure if you can add an unbound PK field to the table.

HTH,
Eric Cadwell
http://www.origincontrols.com

pcPirate said:
Dmitriy,
Thanks a lot for the reply,
My database table to be displayed in the datagrid has a lot of fields and it
would be quite unwise to use the dataTable (which is needed in your example)
Is there anyway still to work around with dataset? All I ask is just to get
the exact row of the dataset.

Pls. advise and thanks in advance.
pcPirate


Dmitriy Lapshin said:
Hi,

There's a thread in the windowsforms.controls newsgroup titled
"How to find data in sorted DataGrid control". I have given an example of
accessing the appropriate DataRow there.

--
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

pcPirate said:
Hi,
I've followed some advice through this forum in which I would change the
dataset value in order to change the particular cell value in datagrid via
coding.

What I'm doing now is that, if I change the first column, the second column
in the same row would display the same input as the first's. The way I did
is to take the row no. of the column edited and update the dataset in the
same row, second column. However, the datagrid actually allowed
sorting
and
once the it is sorted, the row to be updated in dataset would be incorrect.

Question is:
i) Is there any better way to update the dataset?

Pls advise and thanks in advance.
pcPirate
 
That's a good idea... However, is Datagrid really that weak?? I mean, it's
suppose to bind the the dataset but how come there's isn't a good way to
retrieve the exact row of the dataset? isn't this a bit stupid?
 
DataSets themselves do not contain rows. They contain DataTables which, in
turn, contain DataRows.
 
Dmitriy,
Okay,
i) Your example apply to DataTable
ii) My datagrid bind to DataSet

What should I do to relate the my DataSet to your example ?

pcPirate
 
Almost nothing - the DataView returned by the appropriate CurrencyManager's
List property will already be returning the rows for a data table or a data
relation determined by the DataMember argument value for which the
CurrencyManager instance had been queried from the form's Binding Context.

So choose the DataMember argument value wisely. For parent table, it will
correspond to the table name (the TableName property value, to be exact).
For child table, the DataMember will look like:

ParentTableName.RelationName

Of course you will be provided with DataRowView instances by indexing the
DataView returned, but each DataRowView has a Row property returning the
actual, live underlying DataRow instance.

--
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
 
Dmitriy,
Thank you very very very ver..........y much!!!! I've finally got it.

Thanks a lot!!!

pcPirate.
 
Back
Top