hiding Id when binding to datagrid

Posts   
 
    
Gaston
User
Posts: 10
Joined: 24-Jul-2005
# Posted on: 24-Jul-2005 12:12:17   

Hi,

I have a table with an autoincrement Id and I want to show that table (with tables to which it relates, so I use a typed list) in a datagrid. But I don't want to show the Id to the users (because it is meaningless). But when I, for example, want to show the orders for that customer, I need the CustomerId! (but this not in my typed list, as I don't want to show it in the datagrid. How can I solve this?

Thanks!

Gaston Vaessen

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 24-Jul-2005 12:23:14   

In your grid control, hide the column. It's a thing you can control with the grid you're using, at least with most grids simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Gaston
User
Posts: 10
Joined: 24-Jul-2005
# Posted on: 24-Jul-2005 13:29:29   

Thanks for your superfast reply. I can't find how to hide a column in the standard VS 2003 datagrid, but I found a solution by creating an own TableStyle (and not include that field)...

Gaston
User
Posts: 10
Joined: 24-Jul-2005
# Posted on: 24-Jul-2005 13:55:41   

But now there is a new problem. I use this to get the right data out of the datagrid: Dim countryRow As CountryOverzichtRow countryRow = Me._countryOverzicht(Me.grdCountry.CurrentRowIndex)

But when the user use sorting on the datagrid, this doesn't work (I get the wrong record).

How can i solve this? I looked at your Northwind example, but you're not allowing sorting...?

Thanks,

Gaston Vaessen

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 25-Jul-2005 10:07:11   

I think you should use the grid's actual data row object to get the object to work with, not use the index. I'm not sure which grid you're using, it depends on the grid how to obtain the real dataobject unfortunately.

Frans Bouma | Lead developer LLBLGen Pro
Gaston
User
Posts: 10
Joined: 24-Jul-2005
# Posted on: 25-Jul-2005 12:34:33   

Yes, I'm trying that... but that ******* datagrid control is making me mad. I'm using the standard VS 2003 datagrid control...

Rogelio
User
Posts: 221
Joined: 29-Mar-2005
# Posted on: 25-Jul-2005 14:50:35   

Hi,

To get the right row from any DataGrid, the best option is to use the CurrencyManager's Position property. To get the CurrencyManager object that is controlling your collection of rows, use the BindingContext object of your form.

Gaston
User
Posts: 10
Joined: 24-Jul-2005
# Posted on: 25-Jul-2005 18:57:16   

Can you please explain how? I use this:

Dim cm As CurrencyManager = CType(BindingContext(_codenumbersOverzicht), CurrencyManager) Dim codenumberId As Integer = CType(cm.List, DataView).Table.Rows(cm.Position).Item(0)

It works great... when sorting isn't applied... when I click to sort on a column, it goes wrong...

Thanks!

Rogelio
User
Posts: 221
Joined: 29-Mar-2005
# Posted on: 25-Jul-2005 20:00:08   

Gaston wrote:

Can you please explain how? I use this:

Dim cm As CurrencyManager = CType(BindingContext(_codenumbersOverzicht), CurrencyManager) Dim codenumberId As Integer = CType(cm.List, DataView).Table.Rows(cm.Position).Item(0)

It works great... when sorting isn't applied... when I click to sort on a column, it goes wrong...

Thanks!

In your case try:

codenumberId = CType(cm.Current,DataRowView).Row.Item(0)

Gaston
User
Posts: 10
Joined: 24-Jul-2005
# Posted on: 25-Jul-2005 21:00:35   

It works!! smile

thanks!! wink

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 25-Jul-2005 21:07:23   

great info, Rogelio simple_smile

Frans Bouma | Lead developer LLBLGen Pro