Datagridview display password column and add any controls

Source: Internet
Author: User

 

When the cell content needs to be formatted for display.
For example:

Code 

/// <Summary>

///Cell display format event

/// </Summary>

/// <Param name = "sender"> </param>

/// <Param name = "E"> </param>

Private VoidMaid (ObjectSender,

Datagridviewcellformattingeventargs E)

{

//Display the number * in the 4th column. The number * is the same as the actual data length.

If(E. columnindex =3)

{

If(E. value! =Null& Amp; E. value. tostring (). Length & gt;0)

{

E. value =New String('*', E. value. tostring (). Length );

}

}

}

 
 
 
The datagridview. editingcontrolshowing event occurs when the control used to edit cells is displayed.

///   <Summary>
/// Edit a cell control event
///   </Summary>

///   <Param name = "sender"> </param>
///   <Param name = "E"> </param>
Private Void Datagridview1_editingcontrolshowing ( Object Sender, datagridvieweditingcontrolshowingeventargs E)

{

// when editing the 4th column, the 4th column is displayed as the * number
textbox T = E. control as textbox;
If (T! = null )

{

If(This. Maid. columnindex =3)
T. passwordchar ='*';
Else
T. passwordchar =New Char();
 
}
 
}

 

Datagridview add any controls

Void Datagridview2_editingcontrolshowing ( Object Sender, datagridvieweditingcontrolshowingeventargs E)
{
If (E. Control Is Datagridviewtextboxeditingcontrol)
{
Textbox = (textbox) E. Control;
// Panel P = (panel) textbox. parent; // Finding the current parent control is actually a panel. You can clear the control in this panel, and then you can add any control to the Panel and layout it at will.
Panel P = (panel) E. Control. parent;
P. Controls. Clear ();

BTN. width = 38 ;
BTN. Text = textbox. text;
BTN. Click + = New Eventhandler (btn_click );
P. Controls. Add (BTN );
}

}
 
 
 
Add controls using a container (panel.

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.