【接下】
// Implements the IDataGridViewEditingControl
// .EditingPanelCursor property.
public Cursor EditingPanelCursor
{
get
{
return base.Cursor;
}
}
//protected override void OnValueChanged(EventArgs eventargs)
//{
// // Notify the DataGridView that the contents of the cell
// // have changed.
// valueChanged = true;
// this.EditingControlDataGridView.NotifyCurrentCellDirty(true);
// base.OnValueChanged(eventargs);
//}
//protected override void OnValueChanged(object o,EventArgs eventargs)
//{
// // Notify the DataGridView that the contents of the cell
// // have changed.
// valueChanged = true;
// this.EditingControlDataGridView.NotifyCurrentCellDirty(true);
// base.OnValueChanged(o ,eventargs);
//}
//protected override void OnCheckedChanged(EventArgs e)
//{
// // Notify the DataGridView that the contents of the cell
// // have changed.
// // base.OnValueChanged(eventargs);
// base.OnCheckedChanged(e);
//}
protected override void OnClick(EventArgs e)
{
valueChanged = true;
this.EditingControlDataGridView.NotifyCurrentCellDirty(true);
string s = (string)EditingControlFormattedValue;
base.OnClick(e);
}
// protected override void on
public void test()
{
// this .m
}
}
/// <summary>
/// 独立的RadioButtonList控件
/// </summary>
[Designer(typeof(MyRadioListControl.AddRadioButtonItemDesigner))]
public class MyRadioListControl : System.Windows.Forms.Panel
{
public List<RadioButton> radioButtons = new List<RadioButton>();
[Browsable(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]
public virtual List<RadioButton> myRadioButtonItem
{
get
{
return radioButtons;
}
set
{
radioButtons = value;
}
}
public int columns = 5;
public int rows = 1;
public Arrangement arrangement = Arrangement.Compact;
public string value;
[Browsable(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public string myValue
{
get { return value; }
set
{
this.value = value;
foreach (RadioButton rb in this.myRadioButtonItem)
{
try
{
if (this.value == rb.Tag.ToString())
{
rb.Checked = true;
return;
}
else
{
rb.Checked = false;
}
}
catch
{ rb.Checked = false; }
}
}
}
protected virtual void OnRadioButtonItemCheckedChanged(object sender, EventArgs e)
{
}
protected virtual void OnValueChanged(EventArgs e)
{
foreach (RadioButton rb in this.myRadioButtonItem)
{
try
{
if (this.value == rb.Tag.ToString())
{
rb.Checked = true;
return;
}
else
{
rb.Checked = false;
}
}
catch
{ rb.Checked = false; }
}
}
protected virtual void OnSelectedIndexChanged(EventArgs e)
{}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible), DefaultValue(Arrangement.Compact)]
public Arrangement myArrangement
{
get
{
return arrangement;
}
set
{
arrangement = value;
}
}
public enum Arrangement
{
Compact,
Equally,
}
[Browsable(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible), DefaultValue(5)]
public int myColumns
{
get
{
return columns;
}
set
{
columns = value;
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible), DefaultValue("5")]
public int myRows
{
get
{
return rows;
}
set
{
rows = value;
}
}
public MyRadioListControl()
{
}
public MyRadioListControl(int RadioButtonCount)
{
for (int a = 0; a < RadioButtonCount; a++)
{
this.myRadioButtonItem.Add(new RadioButton());
}
}
public RadioButton getCheckedRadioButton()
{
foreach (RadioButton rb in this.myRadioButtonItem)
{
if (rb.Checked == true)
{
return rb;
}
}
return null;
}
/// <summary>
/// 获取或设置RadioButtonItems集合
/// </summary>
// [Localizable(true), SRCategory("CatBehavior"), SRDescription("TreeViewNodesDescr"), MergableProperty(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
//private void RadioButtonItemChecked(object sender, EventArgs e)
//{
// if (((RadioButton)sender).Checked == true)
// {
// // this.NotifyCurrentCellDirty(true);
// // this .AccessibilityNotifyClients ( AccessibleEvents.ValueChange ,
// this.Value = ((RadioButton)sender).Tag.ToString();
// }
//}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
foreach (RadioButton rb in myRadioButtonItem)
{
//try
//{
// rb.CheckedChanged += new EventHandler(RadioButtonItemChecked);
//}
//catch { }
if (rb.Tag == null) rb.Tag = rb.Text;
this.Controls.Add(rb);
}
// this.Width = new RadioButton().Width * myColumns;
// this.Height =(int)(this.Controls.Count / myColumns);
int a = 0;
foreach (RadioButton rb in myRadioButtonItem)
{
// int rowsTotle = (int )(a / rowcount);
int TheRow = (int)(a / myColumns);
int TheColumn = (a % myColumns);
rb.Location = new Point(TheColumn * rb.Width, TheRow * rb.Height);//纵排
a++;
}
}
public void setControlSize(int with, int heigh)
{
this.Width = with;
this.Height = heigh;
}
public void setRadioButtonTextColor(Color c)
{
foreach (RadioButton rb in this.myRadioButtonItem)
{
rb.ForeColor = c;
}
}
public void setBackColor(Color c)
{
this.BackColor = c;
}
//谓词使用
internal class AddRadioButtonItemDesigner : ControlDesigner
{
private IDesignerHost m_DesignerHost;
private DesignerVerbCollection verbs = null;
private MyRadioListControl HostControl
{
get { return (MyRadioListControl)this.Control; }
}
public IDesignerHost DesignerHost
{
get
{
if (m_DesignerHost == null)
m_DesignerHost = (IDesignerHost)GetService(typeof(IDesignerHost));
return m_DesignerHost;
}
}
public void OnAddItem(object sender, EventArgs e)
{
Control.ControlCollection oldManagedPanels = HostControl.Controls;
//注册通知编译器 控件要变
RaiseComponentChanging(TypeDescriptor.GetProperties(HostControl)["MyRadioListControl"]);
RadioButton rb = ((RadioButton)DesignerHost.CreateComponent(typeof(RadioButton))); ;//这里指示对应代码又编译器产生。
rb.Text = rb.Name;
HostControl.myRadioButtonItem.Add(rb);
HostControl.Controls.Add(rb);
//注册通知编译器,控件已经变。
RaiseComponentChanged(TypeDescriptor.GetProperties(HostControl)["MyRadioListControl"], oldManagedPanels, HostControl.myRadioButtonItem);
((MyRadioListControl)Control).OnPaint(new PaintEventArgs(Control.CreateGraphics(), Control.ClientRectangle));
}
public void OnRemoveItem(object sender, EventArgs e)
{
Control.ControlCollection oldManagedPanels = HostControl.Controls;
if (HostControl.Controls.Count < 1) return;
HostControl.myRadioButtonItem.RemoveAt(HostControl.Controls.Count - 1);
RaiseComponentChanging(TypeDescriptor.GetProperties(HostControl)["RadioButton"]);
DesignerHost.DestroyComponent((RadioButton)HostControl.Controls[HostControl.Controls.Count - 1]);
RaiseComponentChanged(TypeDescriptor.GetProperties(HostControl)["MyRadioListControl"], oldManagedPanels, HostControl.Controls);
}
public override DesignerVerbCollection Verbs
{
get
{
if (verbs == null)
{
verbs = new DesignerVerbCollection();
verbs.Add(new DesignerVerb("Add Item", new EventHandler(OnAddItem)));
verbs.Add(new DesignerVerb("Remove Item", new EventHandler(OnRemoveItem)));
}
return verbs;
}
}
}
}
}
[/code]
PS:之前把【独立的RadioButtonList控件】拖放到 用户控件uc1上,然后编辑radiobutto集合,再从cu1继承编写diyRadioButtonEditingControl,实现cell的编辑控件。一起能很顺利的完成预期功能。但是这样做留下一个后遗症,就是在同一个工程中 若想 在实现 不同个数或者Text的 radiobuttonList column 列的时候,需要再COPY代码编译新的column类型,不灵活。附上此份源码(在我的资源中可下载)
请兄弟姐妹们绑定啊。