The use of the Dev Gridcontrol control selection box

Source: Internet
Author: User

First introduction to the environment: vs2010,dev11.2

The effect you want to achieve: When you click a row in front of the selection box is selected.

I found a lot on the internet, but I felt very different from what I thought (there was a lot more to add another checkbox, which I didn't find in dev)

Here's my approach:

First: Gridcontrol control to be set to non-editable state, under "Optionsbehavior" the value of "Editable" is changed to false, otherwise left-click No use.

The first step:

Enter "Run Designer" to add three columns, mainly about the first column of "Judging column" property settings, which uses the Dev's own property, when adding the column, its properties [Columnedit] from the drop-down box select "Checkedit", and then open the property's down arrow, set its " Valuechecked "and" valueunchecked "type and value, here I used the INT type 1 and the limit as the state indication. "Note: It is best not to use the default bool type of TRUE and false, so easy to appear always can not display the tick check, but with the int type of the situation will not occur; I found the problem: because I used the ToString function, This will automatically change the true or false to uppercase "true" or "false", so the judgment is not correct, modify this point can be correct boulevard purpose "

Another: My approach is mainly that this step is not the same as the internet said, not add a checkbox but with dev own existing properties.

Step Two:

Add the event, select the Gridcontrol GridView, and then add its event "Rowclick", adding the event code as follows:

Private voidGridview1_rowclick (Objectsender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) {            stringMidvaluestr = Gridview1.getdatarow (E.rowhandle) ["Select"].            ToString (); if(Midvaluestr = ="0"|| Midvaluestr = ="") {gridview1.getdatarow (e.rowhandle) ["Select"] =1; }            Else{gridview1.getdatarow (e.rowhandle) ["Select"] =0; }        }

NOTE: The null value in the IF condition determines that my column is newly added after the database is fetched, so its value is empty instead of 0. Therefore, there may be two values, 0 and NULL, when the row is unchecked.

Step Three:

operation, you can achieve the above effects. and in this case, Gridcontrol bound data source, we added the value of the Judgment column is also changed in real time, which is also convenient for subsequent use of values.

Summary:

① online A lot of ways to add a lot of things, the most typical such as adding a checkbox and then change the properties, but also with more than one event, do not know whether I do not understand or I do not fully understand the way those people, anyway, I think it is too complicated, and some control or properties, events I can not find. Don't know why not use dev itself.

② say a few similar events that I tested during the experiment: the Focusedrowchanged event, which occurs when the position of the row is changed (such as dragging a selected row) instead of when you select another row The event focusedrowobjectchanged represents the trigger when the row is selected for change, but this event is also triggered when the control is initially loaded, so I feel very inconvenient; The Cellvaluechanged event can also achieve the above effect, At this point the entire control is editable, but it is necessary to set the editable state of the column according to the requirements of the different columns; Finally, the Rowclick event, which we use above, is the effect that only you click that line to trigger the event.

The use of the Dev Gridcontrol control selection box

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.