sunDAC

i am working in windows 2003 application using c#.

i have already added checkbox in datagrid.

in my application i want that paricular check box should be

bydefault checked and unchecked depending upon values of databse suppose id.

when id=1, checkbox should be checked and when id=0,checkbox should be bydefault unchecked.

i dont know how to check and uncheck bydefault value.

2) Second problem is when i select checkbox then that particular checkbox is clicked and when i select other checkbox

then all the checkbox unchecked.

how to prevent from this problem

i am working in c# using c#.

My code is :

foreach ( DataRow dr2 in ds.Tables["module_master"].Rows)

{

if( Convert.ToInt32(dr2["m_type"].ToString() ) == 1)

{

discontinuedCol = new DataGridBoolColumn();

discontinuedCol.MappingName = "module_id";

discontinuedCol.HeaderText = "Select";

discontinuedCol.Width = 50;

else

{

discontinuedCol = new DataGridBoolColumn();

discontinuedCol.MappingName = "module_id";

discontinuedCol.HeaderText = "Select";

discontinuedCol.Width = 50;

}

}

tableStyle.GridColumnStyles.Add(discontinuedCol);

Anyone help me

Thanks in advance.



Re: Windows Forms Data Controls and Databinding Checkbox in datagrid

in2minds

hi santosh,

here are the solution to your issues, sorry i cant write the code for you in C# since i work with VB2005

1) for checking the checkbox according to the value in your database, make sure you using a Boolean field in your database since you want Yes/No.

2) For your selection problem, make sure your datagridview properties is set to allow MultipleSelect = True

I hope this helps

Mehdi





Re: Windows Forms Data Controls and Databinding Checkbox in datagrid

santosh_dac100

Hi Mehdi,

Thanks For your help.

I am taking yes/no field in database.

But regarding second problem i am using 2003 application and datagrid.

i am not using datagridview.

datagrid dont have a property allow multiple select or allow multiple select property.

Is there any solution





Re: Windows Forms Data Controls and Databinding Checkbox in datagrid

in2minds

hi santosh,

here is the implementation in c#

http://www.codeproject.com/aspnet/ChkBoxInGrid.asp

I would suggest you to upgrade to 2005 Smile, as you get more features with controls.

Thanks

MM





Re: Windows Forms Data Controls and Databinding Checkbox in datagrid

santosh_dac100

Hi Mehdi,

Thanks for your help.

But i am using 2003 windows application and not web application.

i have managed to solve my problem somehow.

But now i have one new problem,i want to add image in datagrid.

i dont know how to insert image in datagrid.

i have tried different code,but that is not working.

i right now cant upgrade from 2003 to 2005.

Do you have in any suggestion

I am using c#.





Re: Windows Forms Data Controls and Databinding Checkbox in datagrid

Gavin Jin - MSFT

Hi,

This article tells you how to get images in a data grid

If you try to display bitmaps in a data grid, you see only a text message for the bitmap. For displaying bitmaps, you must create an own table style for your data grid. Furthermore you need a 'DataGridImageColumn' class for displaying bitmaps in the datagrid. The following code shows how to create your own table style. A DataSet with a table 'Test' is defined previously:

DataGridTableStyle DGStyle;
DataGridColumnStyle GridTextColumn, GridBmpColumn;
DGStyle = new DataGridTableStyle();

// select table
DGStyle.MappingName = "Test";

// get the PropertyDescriptorCollection for the data
// source and data member.
PropertyDescriptorCollection pcol =
    this.BindingContext[DBDataSet,
              "Test"].GetItemProperties();

// create column style for a text column
GridTextColumn = new DataGridTextBoxColumn(pcol["Description"]);
GridTextColumn.MappingName = "Description";
GridTextColumn.HeaderText = "Icon-Name";
GridTextColumn.Width = 200;
DGStyle.GridColumnStyles.Add(GridTextColumn);

// create column style for an image column
GridBmpColumn = new DataGridImageColumn(pcol["Images"]);
GridBmpColumn.MappingName = "Images";
GridBmpColumn.HeaderText = "Bitmap";
GridBmpColumn.Width = 100;
DGStyle.GridColumnStyles.Add(GridBmpColumn);

// add table style to the data grid
dataGrid1.TableStyles.Add(DGStyle);

// connect grid with database
dataGrid1.DataSource = DBDataSet;
dataGrid1.DataMember = DBDataSet.Tables["Test"].TableName;
Fore more information ,check this link
http://www.codeguru.com/Csharp/Csharp/cs_controls/datagrid/article.php/c4783/
Hope it helps