(E-Mail Removed) (drewble) wrote in message news:<(E-Mail Removed)>...
> I'm having similar issues - it's most likely my lack of knowledge for
> the DataGrid, DataTable, DataSet framework... Let me run this by
> you. I have an XML file that I get into a DataSet. I create a
> DataTable with the first table in my DataSet. I then bind this to a
> DataGrid and the 13 columns I want from my original XML file are
> indeed shown in the DataGrid.
>
> Now - what I want to do is add in a 14th column and have it setup as a
> two state checkbox that I can essentially loop through when the user
> is done checking through the various line items.
>
> My thinking was - take the DataTable, create a new DataColumn
> (typeof(bool)), add that DataColumn into the DataTable. Then I tried
> to create a DataGridTableStyle, create a DataGridColumnStyle, map that
> ColumnStyle to my added DataColumn, add that ColumnStyle into my
> DataGridTableStyle and add the TableStyle into my DataGrid.
>
> When I do this, only the checkbox column appears - not the other 13
> rows...
>
> Here is some of my code
>
> DataTable _resultTable = ds.Tables[0] ;
>
> DataColumn cCurrent = new DataColumn("Arbitrated", typeof(bool)) ;
> cCurrent.DefaultValue = false ;
>
> _resultTable.Columns.Add(cCurrent) ;
>
> DataGridTableStyle ts1 = new DataGridTableStyle() ;
> ts1.MappingName = "Result" ;
>
> DataGridColumnStyle boolCol = new DataGridBoolColumn() ;
> boolCol.MappingName = "Arbitrated" ;
> boolCol.HeaderText = "header text" ;
> boolCol.Width = 150 ;
> ((DataGridBoolColumn)boolCol).AllowNull = false;
>
> ts1.GridColumnStyles.Add(boolCol) ;
>
> dataGrid1.TableStyles.Add(ts1) ;
>
> this.dataGrid1.DataSource = _resultTable ;
>
> Again - this correctly sets up a two state column and it shows in the
> DataGrid - but where did my other columns go???
When you don't specify a TableStyle, .NET automatically generates one
based on all the columns in your datatable.
When you specify one, it then doesn't do this.
What you should do, is create a tablestyle with ALL 13+1 columns.
(Tedius, I know).
You can use the designer to help you with this, I generally got fed up
with copy/paste code - I feel fiddle with the designer is easier.
If the dataset is strongly typed - and you can add it to your form,
then it's even easier.
jliu -
www.ssw.com.au -
www.johnliu.net