Job Lot

how can i add a check box to binding navigator control

thanks




Re: Windows Forms General Add check box to Binding Navigator control?

Zhi-Xin Ye - MSFT

Hi,Job Lot

You can wirte a customer ToolStripItem inherited from ToolStripControlHost with a checkbox in it, and add this customer ToolStripItem into the BindingNavigator. And this article would help you.

Regards.

Ye






Re: Windows Forms General Add check box to Binding Navigator control?

Zhi-Xin Ye - MSFT

Hi, Job Lot

I write this sample for your information,

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace Samples

{

public partial class General : Form

{

public General()

{

InitializeComponent();

}

private void General_Load(object sender, EventArgs e)

{

this.bindingNavigator1.Items.Add(new CheckTextBoxToolStripItem() );

}

}

class CheckTextBoxToolStripItem : ToolStripControlHost

{

private FlowLayoutPanel controlPanel;

private CheckBox chk = new CheckBox();

private TextBox txt = new TextBox();

public CheckTextBoxToolStripItem()

: base(new FlowLayoutPanel())

{

// Set up the FlowLayouPanel.

controlPanel = (FlowLayoutPanel)base.Control;

controlPanel.BackColor = Color.Transparent;

// Add two child controls.

chk.AutoSize = true;

controlPanel.Controls.Add(chk);

controlPanel.Controls.Add(txt);

}

public bool TextEnabled

{

get { return chk.Checked; }

set { chk.Checked = value; }

}

protected override void OnSubscribeControlEvents(Control control)

{

base.OnSubscribeControlEvents(control);

chk.CheckedChanged += new EventHandler(CheckedChanged);

}

protected override void OnUnsubscribeControlEvents(Control control)

{

base.OnUnsubscribeControlEvents(control);

chk.CheckedChanged -= new EventHandler(CheckedChanged);

}

private void CheckedChanged(object sender, EventArgs e)

{

// Enable or disable the TextBox according to the

// current CheckBox selection.

txt.Enabled = TextEnabled;

}

}

}

Hope it helps. Best Regards.

Ye






Re: Windows Forms General Add check box to Binding Navigator control?

Job Lot

Hi Zhi-Xin Ye - MSFT

Thanks for the post and it really helped. Another question though, how can I make use of this custom CheckBoxToolStrip item at design time How can i add custom item to the drop down menu of BindingNavigator

Thanks







Re: Windows Forms General Add check box to Binding Navigator control?

Zhi-Xin Ye - MSFT

Hi,Job

To use this Custom CheckBoxStripItem at design time,you can take the following steps:

1. using the Design namespace as:

using System.Windows.Forms.Design;

2. Add the following code in front of the CheckBoxStripItem:

[ToolStripItemDesignerAvailability

(ToolStripItemDesignerAvailability.ToolStrip |

ToolStripItemDesignerAvailability.StatusStrip)]

class CheckTextBoxToolStripItem : ToolStripControlHost

{

//see codes in my last post.

}

3. Rebuild your project,.then switch to design mode, when the click on the smart tag on the BindingNavigator, you will see this custom ToolStripItem is added to the list.

Hope it helps.
Best Regards.
Ye