How to hide a column in a DataGrid

  • Thread starter Thread starter darin_dimitrov
  • Start date Start date
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?
 
Back
Top