HighTechTalks DotNet Forums  

adding a data bound combo box

Dotnet Framework (WinForms DataBinding) microsoft.public.dotnet.framework.windowsforms.databinding


Discuss adding a data bound combo box in the Dotnet Framework (WinForms DataBinding) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
bladecleaver
 
Posts: n/a

Default adding a data bound combo box - 08-14-2008 , 02:35 PM






Can a data bound combo box be added to a toolstrip such as a
bindingnavigator. I can add the toolstrip item, but the databinding
properties are not present. You also cannot drop a databound text on the
toolstrip.

Reply With Quote
  #2  
Old   
Morten Wennevik [C# MVP]
 
Posts: n/a

Default RE: adding a data bound combo box - 08-18-2008 , 12:29 AM







"bladecleaver" wrote:

Quote:
Can a data bound combo box be added to a toolstrip such as a
bindingnavigator. I can add the toolstrip item, but the databinding
properties are not present. You also cannot drop a databound text on the
toolstrip.
You can databind against a ToolstripComboBox, but I'm not sure you can do it
in the designer, and in any case I find doing it in code to be much more
maintainable.

ToolstripComboBox does not derive from Control and therefore does not have
the databinding capabilities you find on a control. It does, however, have a
reference to the ComboBox displayed in its Control property.

ComboBox cb = toolStripComboBox1.Control as ComboBox;
cb.DataSource = CreateKeyValuePairList();
cb.DisplayMember = "Key";
cb.ValueMember = "Value";
cb.DataBindings.Add("SelectedValue", source, "SomeProperty");

--
Happy Coding!
Morten Wennevik [C# MVP]



Reply With Quote
  #3  
Old   
Morten Wennevik [C# MVP]
 
Posts: n/a

Default RE: adding a data bound combo box - 08-18-2008 , 12:29 AM




"bladecleaver" wrote:

Quote:
Can a data bound combo box be added to a toolstrip such as a
bindingnavigator. I can add the toolstrip item, but the databinding
properties are not present. You also cannot drop a databound text on the
toolstrip.
You can databind against a ToolstripComboBox, but I'm not sure you can do it
in the designer, and in any case I find doing it in code to be much more
maintainable.

ToolstripComboBox does not derive from Control and therefore does not have
the databinding capabilities you find on a control. It does, however, have a
reference to the ComboBox displayed in its Control property.

ComboBox cb = toolStripComboBox1.Control as ComboBox;
cb.DataSource = CreateKeyValuePairList();
cb.DisplayMember = "Key";
cb.ValueMember = "Value";
cb.DataBindings.Add("SelectedValue", source, "SomeProperty");

--
Happy Coding!
Morten Wennevik [C# MVP]



Reply With Quote
  #4  
Old   
bladecleaver
 
Posts: n/a

Default RE: adding a data bound combo box - 08-18-2008 , 06:22 AM



Sorry, I was a little to quick to post, and forgot to add I am working with
VB. Thanks for the speedy reply, and I will try to figure the C to VB.

bladecleaver

"Morten Wennevik [C# MVP]" wrote:

Quote:
"bladecleaver" wrote:

Can a data bound combo box be added to a toolstrip such as a
bindingnavigator. I can add the toolstrip item, but the databinding
properties are not present. You also cannot drop a databound text on the
toolstrip.

You can databind against a ToolstripComboBox, but I'm not sure you can do it
in the designer, and in any case I find doing it in code to be much more
maintainable.

ToolstripComboBox does not derive from Control and therefore does not have
the databinding capabilities you find on a control. It does, however, have a
reference to the ComboBox displayed in its Control property.

ComboBox cb = toolStripComboBox1.Control as ComboBox;
cb.DataSource = CreateKeyValuePairList();
cb.DisplayMember = "Key";
cb.ValueMember = "Value";
cb.DataBindings.Add("SelectedValue", source, "SomeProperty");

--
Happy Coding!
Morten Wennevik [C# MVP]


Reply With Quote
  #5  
Old   
bladecleaver
 
Posts: n/a

Default RE: adding a data bound combo box - 08-18-2008 , 06:22 AM



Sorry, I was a little to quick to post, and forgot to add I am working with
VB. Thanks for the speedy reply, and I will try to figure the C to VB.

bladecleaver

"Morten Wennevik [C# MVP]" wrote:

Quote:
"bladecleaver" wrote:

Can a data bound combo box be added to a toolstrip such as a
bindingnavigator. I can add the toolstrip item, but the databinding
properties are not present. You also cannot drop a databound text on the
toolstrip.

You can databind against a ToolstripComboBox, but I'm not sure you can do it
in the designer, and in any case I find doing it in code to be much more
maintainable.

ToolstripComboBox does not derive from Control and therefore does not have
the databinding capabilities you find on a control. It does, however, have a
reference to the ComboBox displayed in its Control property.

ComboBox cb = toolStripComboBox1.Control as ComboBox;
cb.DataSource = CreateKeyValuePairList();
cb.DisplayMember = "Key";
cb.ValueMember = "Value";
cb.DataBindings.Add("SelectedValue", source, "SomeProperty");

--
Happy Coding!
Morten Wennevik [C# MVP]


Reply With Quote
  #6  
Old   
Morten Wennevik [C# MVP]
 
Posts: n/a

Default RE: adding a data bound combo box - 08-18-2008 , 07:02 AM




"bladecleaver" wrote:

Quote:
Sorry, I was a little to quick to post, and forgot to add I am working with
VB. Thanks for the speedy reply, and I will try to figure the C to VB.

bladecleaver

The difference between C# and VB.Net is very small. Basically drop all ;
and change the order of object declaration

Dim cb As ComboBox = ToolStripComboBox1.Control
cb.DataSource = CreateKeyValuePairList()
cb.DisplayMember = "Key"
cb.ValueMember = "Value"
cb.DataBindings.Add("SelectedValue", source, "SomeProperty")

--
Happy Coding!
Morten Wennevik [C# MVP]



Reply With Quote
  #7  
Old   
Morten Wennevik [C# MVP]
 
Posts: n/a

Default RE: adding a data bound combo box - 08-18-2008 , 07:02 AM




"bladecleaver" wrote:

Quote:
Sorry, I was a little to quick to post, and forgot to add I am working with
VB. Thanks for the speedy reply, and I will try to figure the C to VB.

bladecleaver

The difference between C# and VB.Net is very small. Basically drop all ;
and change the order of object declaration

Dim cb As ComboBox = ToolStripComboBox1.Control
cb.DataSource = CreateKeyValuePairList()
cb.DisplayMember = "Key"
cb.ValueMember = "Value"
cb.DataBindings.Add("SelectedValue", source, "SomeProperty")

--
Happy Coding!
Morten Wennevik [C# MVP]



Reply With Quote
  #8  
Old   
bladecleaver
 
Posts: n/a

Default RE: adding a data bound combo box - 08-19-2008 , 07:40 AM



Thank you. That did the trick.

"Morten Wennevik [C# MVP]" wrote:

Quote:
"bladecleaver" wrote:

Sorry, I was a little to quick to post, and forgot to add I am working with
VB. Thanks for the speedy reply, and I will try to figure the C to VB.

bladecleaver


The difference between C# and VB.Net is very small. Basically drop all ;
and change the order of object declaration

Dim cb As ComboBox = ToolStripComboBox1.Control
cb.DataSource = CreateKeyValuePairList()
cb.DisplayMember = "Key"
cb.ValueMember = "Value"
cb.DataBindings.Add("SelectedValue", source, "SomeProperty")

--
Happy Coding!
Morten Wennevik [C# MVP]


Reply With Quote
  #9  
Old   
bladecleaver
 
Posts: n/a

Default RE: adding a data bound combo box - 08-19-2008 , 07:40 AM



Thank you. That did the trick.

"Morten Wennevik [C# MVP]" wrote:

Quote:
"bladecleaver" wrote:

Sorry, I was a little to quick to post, and forgot to add I am working with
VB. Thanks for the speedy reply, and I will try to figure the C to VB.

bladecleaver


The difference between C# and VB.Net is very small. Basically drop all ;
and change the order of object declaration

Dim cb As ComboBox = ToolStripComboBox1.Control
cb.DataSource = CreateKeyValuePairList()
cb.DisplayMember = "Key"
cb.ValueMember = "Value"
cb.DataBindings.Add("SelectedValue", source, "SomeProperty")

--
Happy Coding!
Morten Wennevik [C# MVP]


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.