Datagrid And Checkbox
How to make the arrowpart(which the arrow is on) of datagrid contol turn into the checkbox?
Acutually, data is retrieved from database and showed in the datagrid. I want to add a checkbox option to every row in the datagrid , so the end user can click the checkbox to select the row ,based on the selected rows, I update database.
I have no ideas to implement it. if it won't work, what should I do to select more data from datagrid ?
thanks any help.
I normally us the MSFlexGrid control, but what I do is create a checkbox array, and dynamically size it according to the number of rows.
I've attached a project (still in progress) that shows this in very simple terms...
I tried your code .It is very good. But I have another question about your code. how to scroll the checkbox array when the Msflexgrid is scrolling?
I toss my two cents here.
I use another tecnique. I created two icons, a checkOn and checkOff, that I load in two Image controls, and I display them in the grid using the CellPicture property. In the mouse down event, I check if the mouse is on the picture, and if yes I switch the picture to On to Off and viceversa. I use the RowData propert to reflect the state of the check box for each row. I am saying this is better...
"There are two ways to write error-free programs. Only the third one works."
I'll agree with Marco that his is better for a simple on/off check. For mine, I needed that 3rd state of "grayed", and it needed to really look and act like a checkbox control.
Scrolling (and column resizing) are a problem and require some coding fun. For scrolling, you have to put code in the "Scroll" event (if you have a lot of stuff in the grid list, it can get pretty ugly). For column resize there is no event. I had to use a timer and force a repaint (also ugly. I could have subclassed it, but we will be switching to .NET in a few months, so I went with the easier workaround).
I did it with mstraf'way.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center