PC Review


Reply
Thread Tools Rate Thread

DataGrid and DataTable probs

 
 
Edge
Guest
Posts: n/a
 
      15th Jul 2004
Hey all,

I have a simple datatable consisting of a few columns of the type Boolean
and some rows. Using the defaultView of the table, I connect it to a
dataGrid.
The datagrid automatically displays the table as a grid of checkboxes. You
can set and unset these boxes and the table is updated accordingly.
All works fine accept for two things:
1. I have to select the cell in which the checkbox I want to set is. In
other words, I _always_ need to click twice for a box to set. Is there any
setting to change that?
2. The checkboxes all have 3 possible states: checked, unchecked and checked
with grey background (as if there's some underlying settings you partially
checked). Is it possible to somehow tell the checkboxes they can only be
checked ot unchecked?

Thnx in advance,

Ben


 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmhhcmF0IEJpeWFuaQ==?=
Guest
Posts: n/a
 
      2nd Aug 2004
Hi,

There are 2 options. Either add a datagridstyle to your checkbox column (actually u will have to add the styles to all the columns) and in that you add the foll. line ((DataGridBoolColumn)boolCol).AllowNull = false in the DataGridBoolColumn object.
Other option is to intercept the datagrid mouseup event and change the checkbox state to what u desire.

For more details refer the winform faq URL(http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp)
sections are
5.15 How can I put a checkbox in a column of my DataGrid?
5.80 How can I get a CheckBox column in a DataGrid to react to the first click?


--
Bharat Biyani ((E-Mail Removed))
http://www.orcim.com



"Edge" wrote:

> Hey all,
>
> I have a simple datatable consisting of a few columns of the type Boolean
> and some rows. Using the defaultView of the table, I connect it to a
> dataGrid.
> The datagrid automatically displays the table as a grid of checkboxes. You
> can set and unset these boxes and the table is updated accordingly.
> All works fine accept for two things:
> 1. I have to select the cell in which the checkbox I want to set is. In
> other words, I _always_ need to click twice for a box to set. Is there any
> setting to change that?
> 2. The checkboxes all have 3 possible states: checked, unchecked and checked
> with grey background (as if there's some underlying settings you partially
> checked). Is it possible to somehow tell the checkboxes they can only be
> checked ot unchecked?
>
> Thnx in advance,
>
> Ben
>
>
>

 
Reply With Quote
 
drewble
Guest
Posts: n/a
 
      9th Aug 2004
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???
 
Reply With Quote
 
JohnLiu
Guest
Posts: n/a
 
      10th Aug 2004
(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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataTable -> DataView -> Sort -> DataGrid : need related DataTable index Diamonds Microsoft ADO .NET 4 28th Jun 2006 08:23 PM
Datatable to DataGrid??? =?Utf-8?B?VGltOjouLg==?= Microsoft ASP .NET 1 2nd Jun 2005 03:04 PM
Probs with visual inheritance and DataGrid columns Vladimir Davidov Microsoft Dot NET Framework Forms 0 20th Jan 2005 08:53 AM
Get the Datatable of a DataGrid Kathrin Microsoft Dot NET 0 2nd Jul 2004 10:09 AM
Re: Best way to get a DataTable row from a DataGrid Cor Microsoft VB .NET 0 21st Jan 2004 04:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:13 PM.