How can i add check box in data grid

Hi

I need to add check box in data grid control or any other display control. I am using .net Compact Framework 2.0.

Please tell me how can i do that If it is not supported then how this problem can be solved

Regards



Answer this question

How can i add check box in data grid

  • Biju S Melayil

    I have created a project in C#.net and imported the dll named "DataGridCustomColumns.dll" and used the way you have used in your sample and everything works fine and shows fine i used two controls "DataGridCustomTextBoxColumn" and "DataGridCheckBoxColumn" but when i click the datagrid check box to check or uncheck it takes me to the static void main method and which ever form i have run it says me that {"NullReferenceException"} and if i see its stack trace it shows me "at System.Windows.Forms.GridRenderer._DrawCells()
    at System.Windows.Forms.GridRenderer._Render()
    at System.Windows.Forms.GridRenderer._Render()
    at System.Windows.Forms.DataGridCurrentCell._MoveTo()
    at System.Windows.Forms.DataGridCurrentCell._MoveToChecked()
    at System.Windows.Forms.DataGrid.OnMouseDown()
    at System.Windows.Forms.Control.WnProc()
    at System.Windows.Forms.Control._InternalWnProc()
    at Microsoft.AGL.Forms.EVL.EnterMainLoop()
    at System.Windows.Forms.Application.Run()
    at Nephrology_Client.Program.Main()
    "

    Please tell me what should i do but if i run vb.net application( your code) it works fine.

    Thanks for your replies


  • DavidThi808

    Right, TextBox. That's why it’s a good idea to start a new thread for new question. Answer, however, is valid - if there's some event or functionality missing you'd need to go ahead and implement it.



  • georgeob

    I am unable to understand why if i select the cell it shows the check box but if change focus it shows drawn image that you have done on paint. Cant we show the check box instead of drawing image Please tell.

    If i directly want to show the hosted control mean check box and dont want to show the image drawn how that can be done

    Can you please tell me any third party data grid control that can conatain check boxes Please tell both open source/free and licensed.

    Thanks for the reply.


  • The ZMan

    i wasn't talking about Checkbox.

    Thanks for help.

    "You probably don’t have SP1 installed on device. Make sure you do."



  • jiao

    Please also tell me if i have to catch the check box changed event how can i do that

    Advance Thanks for your reply.


  • Nageshwar

    Because if it's selected, it's a real check box (so you can change it and hook into it’s events just once regardless of current row – to answer your last question). In other case it's a drawn image (which you can change so it looks indistinguishable from a real check box) because it’s faster to draw and much easer to handle in unified manner since there’s only one check box (or other control) to worry about. Also it’s enough to have only one real check box as you can only change current row anyway and it makes no sense to have more from functionality point of view.

    Sure, you as developer can do whatever you like. Just change the code so it would show real check boxes in all rows. As I pointed out it’s not that easy as you need to have and handle many check boxes and redraw them somehow and keep them is some sort of storage and update there values (data binding won’t work as it only good for current row). Also it changes nothing in grid’s behavior so it’s sort of pointless.

    You can find 3rd party grid like controls for NETCF using your favorite search engine.



  • NetPochi

    You have a hosted check box, it has event – simply add handler to it in your code.

    Or perhaps you don’t know how to do that without designers Then see this for both C# and VB syntax.



  • RAED KASSAWAT

  • Christie Myburgh

    If there re no such events on CheckBox, you can't get them and it has absolutely nothing to do with the grid. Create your own check box with these events if needed and use that in the grid.

    You probably don’t have SP1 installed on device. Make sure you do.



  • Klaus Aschenbrenner

    DataGridCustomCheckBoxColumn DataGridCustomCol3 = new DataGridCustomCheckBoxColumn();

    DataGridCustomCol3.Owner = this.dgHospitalVisits;
    DataGridCustomCol3.Format = null;
    DataGridCustomCol3.HeaderText = "2";
    DataGridCustomCol3.MappingName = "Visit_2";
    this.dataGridTableStyle1.GridColumnStyles.Add(DataGridCustomCol3);
    now on addding:
    DataGridCustomCol3.CheckBox.CheckStateChanged +=new EventHandler(CheckBox_CheckStateChanged);

    during running it will generate an error that CheckStateChanged is NULL



  • ListrCZ

    Well! llya Tumanov, sorry in advance but i am unable to understand all what you are trying to say.

    All he wants is to hook check box clicked event in your provided control. i have seen it's code and have been able to find any implementation of onCheckStateEvent Change....

    could you please guide how can i extended it.

    Ilya Tumanov wrote:

    Because if it's selected, it's a real check box (so you can change it and hook into it’s events just once regardless of current row – to answer your last question). In other case it's a drawn image (which you can change so it looks indistinguishable from a real check box) because it’s faster to draw and much easer to handle in unified manner since there’s only one check box (or other control) to worry about. Also it’s enough to have only one real check box as you can only change current row anyway and it makes no sense to have more from functionality point of view.

    Sure, you as developer can do whatever you like. Just change the code so it would show real check boxes in all rows. As I pointed out it’s not that easy as you need to have and handle many check boxes and redraw them somehow and keep them is some sort of storage and update there values (data binding won’t work as it only good for current row). Also it changes nothing in grid’s behavior so it’s sort of pointless.

    You can find 3rd party grid like controls for NETCF using your favorite search engine.



  • ccg420104

    That looks OK to me, probably check box is not created yet at this point. Go ahead and step through with debugger to see why it's not created and change the code accordingly.



  • Tadwick

    Thanks for Checkbox.

    but now there is another issue.

    i want to get the single click or double click event of Textbox...... there is no such even or am i missing some thing.

    2ndly: on deployment of either your application or my own i am getting an error on pda..........

    "Method not found. set_Format in System.Windows.Forms.DatagridTextBoxColumn"



  • How can i add check box in data grid