Hiding one column in Datagrid

nju0843

Member
Joined
Jul 7, 2005
Messages
16
Location
Lafayette, LA
Programming Experience
5-10
***This message is a bit long but please bare with me.***

Hello all,

I have a mySQL table named Budget that
has the following 4 columns:

id, date, starting_balance, remaining_balance
I fill a Datatable with these fields.

I then take the DataTable and bind it to a DataGrid.

The problem is that I don't want the user to see
the id column but I still need the column to be there
in case the user inserts a row, or deletes a row.

I don't see a way for me to "hide" a column in a DataGrid.

I have tried removing the id column from the DataTable before
binding to the Datagrid and then adding the column back before
updating the database, but I get a concurrency exception because
the commandBuilder can apparently detect that I altered the state
of the original Datatable.

Sorry about the length...
Any suggestions?
 
Gambit_NI,

When I type:
dt.Columns(0) there is no apparent visible property.

if you can please show me the code to make the id column
hidden.

That would be great!

Thanks,
nju0843

VB.NET:
[size=1]
 
[/size]
[size=1][color=#0000ff]Private[/color][/size][size=1][color=#0000ff]Sub[/color][/size][size=1] Form1_Load([/size][size=1][color=#0000ff]ByVal[/color][/size][size=1] sender [/size][size=1][color=#0000ff]As[/color][/size][size=1][color=#0000ff]Object[/color][/size][size=1], [/size][size=1][color=#0000ff]ByVal[/color][/size][size=1] e [/size][size=1][color=#0000ff]As[/color][/size][size=1] System.EventArgs) [/size][size=1][color=#0000ff]Handles[/color][/size][size=1][color=#0000ff]MyBase[/color][/size][size=1].Load
[/size][size=1][color=#0000ff]Dim[/color][/size][size=1] dt [/size][size=1][color=#0000ff]As[/color][/size][size=1][color=#0000ff]New[/color][/size][size=1] DataTable
 
[/size][size=1][color=#0000ff]Dim[/color][/size][size=1] dc [/size][size=1][color=#0000ff]As[/color][/size][size=1] DataColumn
 
[/size][size=1][color=#0000ff]Dim[/color][/size][size=1] dr [/size][size=1][color=#0000ff]As[/color][/size][size=1] DataRow
 
[size=1]dc = [/size][size=1][color=#0000ff]New[/color][/size][size=1] DataColumn
 
dc.ColumnName = "id"
 
dt.Columns.Add(dc)
 
dc = [/size][size=1][color=#0000ff]New[/color][/size][size=1] DataColumn
 
dc.ColumnName = "date"
 
dt.Columns.Add(dc)
 
dc = [/size][size=1][color=#0000ff]New[/color][/size][size=1] DataColumn
 
dc.ColumnName = "amount"
 
dt.Columns.Add(dc)
 
[/size][/size][size=1]dr = dt.NewRow()
 
dr.Item(0) = 1
 
dr.Item(1) = "06/06/06"
 
dr.Item(2) = 1000
 
dt.Rows.Add(dr)
 
DataGrid1.DataSource = dt
 
[/size][size=1][color=#0000ff]End[/color][/size][size=1][color=#0000ff]Sub
 
[/color][/size]
 
there is defo a columns property for the datagrid, cause ive used it numerous times

in the property builder (right click on the grid) - in there it allows you to set columns visible/invisible also

do you use AutoGenerateColumns?
 
Back
Top