Datagrid

  • Thread starter Thread starter Jaromir
  • Start date Start date
J

Jaromir

Is there any way for me to fill a row in the datagrid,
from a database, and hide a column? I want to be able to
retrieve the key for the row without displaying it but be
able to access it when selected so that I can access that
key in the database (using SQLCE).
 
Either set the particular column width to 0, or better yet cast
dataGrid.DataSource to DataView and use:
DataRow row = (dataGrid.DataSource as DataView)[dataGrid.CurrentRow].Row;
This will give you direct access to the data table rows.
 
Alex,

Why not set the column with to "-1" to remove the vertical
grid lines of the removed columns?

Regards,
Mikael
-----Original Message-----
Either set the particular column width to 0, or better yet cast
dataGrid.DataSource to DataView and use:
DataRow row = (dataGrid.DataSource as DataView) [dataGrid.CurrentRow].Row;
This will give you direct access to the data table rows.

Jaromir said:
Is there any way for me to fill a row in the datagrid,
from a database, and hide a column? I want to be able to
retrieve the key for the row without displaying it but be
able to access it when selected so that I can access that
key in the database (using SQLCE).


.
 
Could you put that in VB-speak. When I try to convert
your c# to VB it won't let me cast the datasource as a
Dataview. This is what I interpret:

Dim row as DataRow = (dataGrid.DataSource as DataView)
[dataGrid.CurrentRow].Row


-----Original Message-----
Either set the particular column width to 0, or better yet cast
dataGrid.DataSource to DataView and use:
DataRow row = (dataGrid.DataSource as DataView) [dataGrid.CurrentRow].Row;
This will give you direct access to the data table rows.

Jaromir said:
Is there any way for me to fill a row in the datagrid,
from a database, and hide a column? I want to be able to
retrieve the key for the row without displaying it but be
able to access it when selected so that I can access that
key in the database (using SQLCE).


.
 
A better solution is to create a DataGridTableStyle for your table and only
add the columns that you desire to the DataGridTableStyle. This allows you
to have any number of rows in your datatable that are not actually
displayed in the DataGrid.

David Wrighton
.NET Compact Framework

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| Content-Class: urn:content-classes:message
| From: "Mikael" <[email protected]>
| Sender: "Mikael" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: Datagrid
| Date: Mon, 15 Sep 2003 14:17:29 -0700
| Lines: 30
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcN7zsTqggyZZkTxT9uvOCFibKVP7A==
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| Path: cpmsftngxa07.phx.gbl
| Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.framework.compactframework:33407
| NNTP-Posting-Host: tk2msftngxa09.phx.gbl 10.40.1.161
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Alex,
|
| Why not set the column with to "-1" to remove the vertical
| grid lines of the removed columns?
|
| Regards,
| Mikael
|
| >-----Original Message-----
| >Either set the particular column width to 0, or better
| yet cast
| >dataGrid.DataSource to DataView and use:
| >DataRow row = (dataGrid.DataSource as DataView)
| [dataGrid.CurrentRow].Row;
| >This will give you direct access to the data table rows.
| >
| >| >> Is there any way for me to fill a row in the datagrid,
| >> from a database, and hide a column? I want to be able
| to
| >> retrieve the key for the row without displaying it but
| be
| >> able to access it when selected so that I can access
| that
| >> key in the database (using SQLCE).
| >
| >
| >.
| >
|
 
Dim row as DataRow = CType(dataGrid.DataSource,
DataView)(dataGrid.CurrentRowIndex).Row


Jaromir said:
Could you put that in VB-speak. When I try to convert
your c# to VB it won't let me cast the datasource as a
Dataview. This is what I interpret:

Dim row as DataRow = (dataGrid.DataSource as DataView)
[dataGrid.CurrentRow].Row


-----Original Message-----
Either set the particular column width to 0, or better yet cast
dataGrid.DataSource to DataView and use:
DataRow row = (dataGrid.DataSource as DataView) [dataGrid.CurrentRow].Row;
This will give you direct access to the data table rows.

Jaromir said:
Is there any way for me to fill a row in the datagrid,
from a database, and hide a column? I want to be able to
retrieve the key for the row without displaying it but be
able to access it when selected so that I can access that
key in the database (using SQLCE).


.
 
David Wrighton said:
A better solution is to create a DataGridTableStyle for your table and only
add the columns that you desire to the DataGridTableStyle. This allows you
to have any number of rows in your datatable that are not actually
displayed in the DataGrid.

I think "to have any number of rows" was a typo. It obviously should have
been "to have any number of columns"
 
Thanks for your suggestions. While I was waiting for
your reply I was also looking at the DataGridTableStyle.

Can you recommend any sites or MS area that has more info
on how to use the CF controls to their best utility,
rather than resorting to my hunt and peck method? I've
found many sites dealing with the Datagrid and ASP.NET,
but very few with VB.NET and even hardle any with the CF.
 
Very neat. Thank you for that.

John.

Alex Feinman said:
Either set the particular column width to 0, or better yet cast
dataGrid.DataSource to DataView and use:
DataRow row = (dataGrid.DataSource as DataView)[dataGrid.CurrentRow].Row;
This will give you direct access to the data table rows.

Jaromir said:
Is there any way for me to fill a row in the datagrid,
from a database, and hide a column? I want to be able to
retrieve the key for the row without displaying it but be
able to access it when selected so that I can access that
key in the database (using SQLCE).
 
Yes, that is quite easy.

Create a DataAdapter
Create a DataTable

Define the Columns for the table (tbl) from the DataAdapter
DataAdapter.FillSchema(tbl,SchemaType.Mapped);

Fill the tbl with Data from your database:

DataAdapter.Fill(tbl);

bind your datagrid (datagrid1) to a dataview of that table

DataView myView = new DataView(tbl);
datagrid1.DataSource = myView
now you can determine the primary key of the current record by getting the

object PrimKey =
myView[this.dataGrid1.CurrentCell.RowNumber].Row["MyPrimaryKeyColumnName"];

This might not be the fastest and most elegant way, but it worked for me.
 
Back
Top