display checkbox in columns of datagrid
-
i have 4 columns in my datagrid which at the moment are displaying "yes" or "no". My boss wants these existing columns to display checkboxes instead. Ive tried really hard to find a solution to this problem but so far nothing has worked :( Any help would be greatly appreciated - getting desparate now!! Chrissy Callen
-
i have 4 columns in my datagrid which at the moment are displaying "yes" or "no". My boss wants these existing columns to display checkboxes instead. Ive tried really hard to find a solution to this problem but so far nothing has worked :( Any help would be greatly appreciated - getting desparate now!! Chrissy Callen
DataGridCheckBoxColumn class is there in the API. What is the problem for u in using it?
-
DataGridCheckBoxColumn class is there in the API. What is the problem for u in using it?
basically im very new to this :) i need code examples to help me figure it out. How exactly do i apply DataGridCheckBoxColumn to any particular column that already exists in my datagrid?? Chrissy Callen
-
basically im very new to this :) i need code examples to help me figure it out. How exactly do i apply DataGridCheckBoxColumn to any particular column that already exists in my datagrid?? Chrissy Callen
Sorry it is DataGridBoolColumn class. An example is available in MSDN. Just I m giving it below.. using System; using System.Data; using System.Windows.Forms; using System.Drawing; using System.ComponentModel; public class MyForm : Form { private DataTable myTable; private DataGrid myGrid = new DataGrid(); public MyForm() : base() { try { InitializeComponent(); myTable = new DataTable("NamesTable"); myTable.Columns.Add(new DataColumn("Name")); DataColumn column = new DataColumn ("id", typeof(System.Int32)); myTable.Columns.Add(column); myTable.Columns.Add(new DataColumn("calculatedField", typeof(bool))); DataSet namesDataSet = new DataSet(); namesDataSet.Tables.Add(myTable); myGrid.SetDataBinding(namesDataSet, "NamesTable"); AddTableStyle(); AddData(); } catch (System.Exception exc) { Console.WriteLine(exc.ToString()); } } private void grid_Enter(object sender, EventArgs e) { myGrid.CurrentCell = new DataGridCell(2,2); } private void AddTableStyle() { // Map a new TableStyle to the DataTable. Then // add DataGridColumnStyle objects to the collection // of column styles with appropriate mappings. DataGridTableStyle dgt = new DataGridTableStyle(); dgt.MappingName = "NamesTable"; DataGridTextBoxColumn dgtbc = new DataGridTextBoxColumn(); dgtbc.MappingName = "Name"; dgtbc.HeaderText= "Name"; dgt.GridColumnStyles.Add(dgtbc); dgtbc = new DataGridTextBoxColumn(); dgtbc.MappingName = "id"; dgtbc.HeaderText= "id"; dgt.GridColumnStyles.Add(dgtbc); DataGridBoolColumn db = new DataGridBoolColumn(); db.HeaderText= "less than 1000 = blue"; db.Width= 150; db.MappingName = "calculatedField"; dgt.GridColumnStyles.Add(db); myGrid.TableStyles.Add(dgt); // This expression instructs the grid to change // the color of the inherited DataGridBoolColumn // according to the value of the id field. If it's // less than 1000, the row is blue. Otherwise, // the color is yellow. db.Expression = "id < 1000"; } private void AddData() { // Add data with varying numbers for the id field. // If the number is over 1000, the cell will paint // yellow. Otherwise, it will be blue. DataRow dRow = myTable.NewRow(); dRow["Name"] = "name 1 "; dRow["id"] = 999; myTable.Rows.Add(dRow); dRow = myTable.NewRow(); dRow["Name"] = "name 2"; dRow["id"] = 2300; myTable.Rows.Add(dRow); dR
-
Sorry it is DataGridBoolColumn class. An example is available in MSDN. Just I m giving it below.. using System; using System.Data; using System.Windows.Forms; using System.Drawing; using System.ComponentModel; public class MyForm : Form { private DataTable myTable; private DataGrid myGrid = new DataGrid(); public MyForm() : base() { try { InitializeComponent(); myTable = new DataTable("NamesTable"); myTable.Columns.Add(new DataColumn("Name")); DataColumn column = new DataColumn ("id", typeof(System.Int32)); myTable.Columns.Add(column); myTable.Columns.Add(new DataColumn("calculatedField", typeof(bool))); DataSet namesDataSet = new DataSet(); namesDataSet.Tables.Add(myTable); myGrid.SetDataBinding(namesDataSet, "NamesTable"); AddTableStyle(); AddData(); } catch (System.Exception exc) { Console.WriteLine(exc.ToString()); } } private void grid_Enter(object sender, EventArgs e) { myGrid.CurrentCell = new DataGridCell(2,2); } private void AddTableStyle() { // Map a new TableStyle to the DataTable. Then // add DataGridColumnStyle objects to the collection // of column styles with appropriate mappings. DataGridTableStyle dgt = new DataGridTableStyle(); dgt.MappingName = "NamesTable"; DataGridTextBoxColumn dgtbc = new DataGridTextBoxColumn(); dgtbc.MappingName = "Name"; dgtbc.HeaderText= "Name"; dgt.GridColumnStyles.Add(dgtbc); dgtbc = new DataGridTextBoxColumn(); dgtbc.MappingName = "id"; dgtbc.HeaderText= "id"; dgt.GridColumnStyles.Add(dgtbc); DataGridBoolColumn db = new DataGridBoolColumn(); db.HeaderText= "less than 1000 = blue"; db.Width= 150; db.MappingName = "calculatedField"; dgt.GridColumnStyles.Add(db); myGrid.TableStyles.Add(dgt); // This expression instructs the grid to change // the color of the inherited DataGridBoolColumn // according to the value of the id field. If it's // less than 1000, the row is blue. Otherwise, // the color is yellow. db.Expression = "id < 1000"; } private void AddData() { // Add data with varying numbers for the id field. // If the number is over 1000, the cell will paint // yellow. Otherwise, it will be blue. DataRow dRow = myTable.NewRow(); dRow["Name"] = "name 1 "; dRow["id"] = 999; myTable.Rows.Add(dRow); dRow = myTable.NewRow(); dRow["Name"] = "name 2"; dRow["id"] = 2300; myTable.Rows.Add(dRow); dR
thanks but is there any chance of having this in vb.net code please?? Chrissy Callen
-
thanks but is there any chance of having this in vb.net code please?? Chrissy Callen
Imports System Imports System.Data Imports System.Windows.Forms Imports System.Drawing Imports System.ComponentModel Public Class MyForm Inherits System.Windows.Forms.Form Private components As System.ComponentModel.Container Private myTable As DataTable Private myGrid As DataGrid = New DataGrid Public Shared Sub Main() Application.Run(New MyForm) End Sub Public Sub New() Try InitializeComponent() myTable = New DataTable("NamesTable") myTable.Columns.Add(New DataColumn("Name")) Dim column As DataColumn = New DataColumn _ ("id", GetType(System.Int32)) myTable.Columns.Add(column) myTable.Columns.Add(New DataColumn _ ("calculatedField", GetType(Boolean))) Dim namesDataSet As DataSet = New DataSet("myDataSet") namesDataSet.Tables.Add(myTable) myGrid.SetDataBinding(namesDataSet, "NamesTable") AddData() AddTableStyle() Catch exc As System.Exception Console.WriteLine(exc.ToString) End Try End Sub Private Sub AddTableStyle() ' Map a new TableStyle to the DataTable. Then ' add DataGridColumnStyle objects to the collection ' of column styles with appropriate mappings. Dim dgt As DataGridTableStyle = New DataGridTableStyle dgt.MappingName = "NamesTable" Dim dgtbc As DataGridTextBoxColumn = _ New DataGridTextBoxColumn dgtbc.MappingName = "Name" dgtbc.HeaderText = "Name" dgt.GridColumnStyles.Add(dgtbc) dgtbc = New DataGridTextBoxColumn dgtbc.MappingName = "id" dgtbc.HeaderText = "id" dgt.GridColumnStyles.Add(dgtbc) Dim db As DataGridBoolColumnInherit = _ New DataGridBoolColumnInherit db.HeaderText = "less than 1000 = blue" db.Width = 150 db.MappingName = "calculatedField" dgt.GridColumnStyles.Add(db) myGrid.TableStyles.Add(dgt) ' This expression instructs the grid to change ' the color of the inherited DataGridBoolColumn ' according to the value of the id field. If it's ' less than 1000, the row is blue. Otherwise, ' the color is yellow. 'db.Expression = "id < 1000" End Sub Private Sub AddData() ' Add data with varying numbers for the id field. ' If the number is over 1000,
-
Imports System Imports System.Data Imports System.Windows.Forms Imports System.Drawing Imports System.ComponentModel Public Class MyForm Inherits System.Windows.Forms.Form Private components As System.ComponentModel.Container Private myTable As DataTable Private myGrid As DataGrid = New DataGrid Public Shared Sub Main() Application.Run(New MyForm) End Sub Public Sub New() Try InitializeComponent() myTable = New DataTable("NamesTable") myTable.Columns.Add(New DataColumn("Name")) Dim column As DataColumn = New DataColumn _ ("id", GetType(System.Int32)) myTable.Columns.Add(column) myTable.Columns.Add(New DataColumn _ ("calculatedField", GetType(Boolean))) Dim namesDataSet As DataSet = New DataSet("myDataSet") namesDataSet.Tables.Add(myTable) myGrid.SetDataBinding(namesDataSet, "NamesTable") AddData() AddTableStyle() Catch exc As System.Exception Console.WriteLine(exc.ToString) End Try End Sub Private Sub AddTableStyle() ' Map a new TableStyle to the DataTable. Then ' add DataGridColumnStyle objects to the collection ' of column styles with appropriate mappings. Dim dgt As DataGridTableStyle = New DataGridTableStyle dgt.MappingName = "NamesTable" Dim dgtbc As DataGridTextBoxColumn = _ New DataGridTextBoxColumn dgtbc.MappingName = "Name" dgtbc.HeaderText = "Name" dgt.GridColumnStyles.Add(dgtbc) dgtbc = New DataGridTextBoxColumn dgtbc.MappingName = "id" dgtbc.HeaderText = "id" dgt.GridColumnStyles.Add(dgtbc) Dim db As DataGridBoolColumnInherit = _ New DataGridBoolColumnInherit db.HeaderText = "less than 1000 = blue" db.Width = 150 db.MappingName = "calculatedField" dgt.GridColumnStyles.Add(db) myGrid.TableStyles.Add(dgt) ' This expression instructs the grid to change ' the color of the inherited DataGridBoolColumn ' according to the value of the id field. If it's ' less than 1000, the row is blue. Otherwise, ' the color is yellow. 'db.Expression = "id < 1000" End Sub Private Sub AddData() ' Add data with varying numbers for the id field. ' If the number is over 1000,
that was quick :) im very impressed..thank you..will give that a go right now. Chrissy Callen
-
i have 4 columns in my datagrid which at the moment are displaying "yes" or "no". My boss wants these existing columns to display checkboxes instead. Ive tried really hard to find a solution to this problem but so far nothing has worked :( Any help would be greatly appreciated - getting desparate now!! Chrissy Callen
-
well at the moment i'm looking into creating a listview instead on the advice of one of my colleagues :) Chrissy Callen