How to hide a column in a DataGrid

D

darin_dimitrov

Hello,

I have a System.Windows.Forms.DataGrid which is bound to a DataSet
containing a table and columns such as user_id, user_firstname,
user_lastname, etc... How can I force the DataGrid component NOT to
display the user_id column without narrowing my sql query because the
program logic needs this column. I tried the following:

DataSet1.ReadXml('users.xml');
DataSet1.Tables['users'].Columns['user_id'].ColumnMapping :=
MappingType.Hidden;

This code works well and prevents the user_id column from being
displayed in the DataGrid. I can also access the values of the user_id
column programatically by calling:

string currentUserId =
DataSet1.Tables['users'].Rows[DataSet1.CurrentRowIndex].Item['user_id'].ToString();

The problem is when I call DataSet1.WriteXml('users.xml'); to save
back any changes to the underlying backend - the "user_id" attribute is
not persisted at all and the structure of the xml file is modified!!
Could you please help me with this issue?
 

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