datagrid| problem when we first contact the DataGrid, may not be familiar with it, and sometimes some common settings will let you worry for a long time, in view of this, I summed up its more common usage, I hope to have just contact the DataGrid people some help.
A pair of each column to make some settings, here we have a certain understanding of the DataGrid column, its columns can be divided into two types, DataGridTextBoxColumn and DataGridBoolColumn. Of course you can also add the style of your own column, as long as you inherit DataGridColumnStyle (and of course rewrite some methods).
Colu. Mappingname= "Isselect";//Map to a column of a table
Colu. Headertext= ""; Header Name of column
Colu. Truevalue= "Y"; The value of the tick
Colu. Falsevalue= "N";
Colu. width=40; Set the width of the column to be changed
Colu. Allownull=false; Null value not allowed
Colu. Readonly=true; Set the Change column to read-only
Style. Gridcolumnstyles.add (Colu);
The code above is to create a datagridboolcolumn column, which is a checkbox column, there are three states of the checkbox, True,false,null, you can set the Colu. Allownull=false; cancel the third State.
And look at a piece of code, which is creating DataGridTextBox columns
Col. alignment=horizontalalignment.right;//the alignment of the column
Col. format= "#,###.00"; Set the format of the display
Col. width=90;
Style. Gridcolumnstyles.add (COL);
Believe that these two pieces of code should let you have the DataGrid column settings have a certain understanding of it!
Two capture the double click event in the DataGrid, it was a very simple question, but if you only write a program to the doubleclicked of the DataGrid, you will find a problem, in the cell of the DataGrid, double-click without reaction, This is because there is a textbox in the DataGrid, so you need to capture the doubleclicked event of the textbox, but when you complete this step, see how it works, and if you are careful, you will find a problem when the cursor is not in a cell, Double-click the cell and find out what? No reaction, did you double click, why? This is because the DataGrid decomposes this double-click operation, divided into two clicks, the first one to get the cell cursor, the second is to click the event, so your double-click will not respond, so we have to do is to take this action as a double-click event to deal with, so as to achieve our goal. So capturing a double click event will do three things. Here's a piece of code.
if (DateTime.Now < Gridmousedowntime.addmilliseconds (systeminformation.doubleclicktime))
If the time of two clicks is less than the double-click time of the system, we think of it as a double click operation
{
This.frmrolerightshow ();
}
}
How do I get the value of a cell? One line of code, as follows:
String Strrole=dgrole[row,column]. ToString ();
The above is I through see csdn on the post and in practice summed up, if you have any experience of the use of the DataGrid, you might as well write it out and share with you.
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.