Click here to Skip to main content
15,895,485 members
Home / Discussions / C#
   

C#

 
GeneralRe: Control handles via drag event ? Pin
Nick Parker30-Jun-04 8:03
protectorNick Parker30-Jun-04 8:03 
AnswerRe: Control handles via drag event ? Pin
StealthyMark4-Jul-04 7:30
StealthyMark4-Jul-04 7:30 
GeneralQuestion on simple binding Pin
Brett Slaski30-Jun-04 4:26
Brett Slaski30-Jun-04 4:26 
GeneralRe: Question on simple binding Pin
Heath Stewart30-Jun-04 8:46
protectorHeath Stewart30-Jun-04 8:46 
GeneralRe: Question on simple binding Pin
Brett Slaski30-Jun-04 9:24
Brett Slaski30-Jun-04 9:24 
GeneralRe: Question on simple binding Pin
Heath Stewart30-Jun-04 18:08
protectorHeath Stewart30-Jun-04 18:08 
GeneralRe: Question on simple binding Pin
Brett Slaski1-Jul-04 2:44
Brett Slaski1-Jul-04 2:44 
GeneralRe: Question on simple binding Pin
Heath Stewart1-Jul-04 4:36
protectorHeath Stewart1-Jul-04 4:36 
Both of those overloads to the same thing. The first actually uses the params to construct a Binding instance and then calls the second overload.

The thing about binding contexts is that they must be bound exactly the same. So, if you bind a ComboBox to a DataTable, then the Binding must also be bound to a DataTable.

I threw together a quick example. The ComboBox.DataSource is bound to a DataTable (in a DataSet). The DisplayMember and ValueMember specify column names (say, "ID" and "Name").

I also defined a property (SelectedValue) that reflects ComboBox.SelectedValue and created a binding in my ctor like so:
this.DataBindings.Add("SelectedValue", dataSet1, "Table1.ID");
The really important part is how you get the binding context. For the back and previous buttons, I threw together this:
private void button1_Click(object sender, System.EventArgs e)
{
  CurrencyManager cm = (CurrencyManager)this.BindingContext
    [this.dataSet1.Table1]; // typed dataset, so table is a prop
  if (cm != null)
    if (cm.Position >= 1) cm.Position--;
}

private void button2_Click(object sender, System.EventArgs e)
{
  CurrencyManager cm = (CurrencyManager)this.BindingContext
    [this.dataSet1.Table1]; // typed dataset, so table is a prop
  if (cm != null)
    if (cm.Position < cm.Count - 1) cm.Position++;
}
Notice that the BindingContext is the table itself - the same as was bound to the ComboBox.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Question on simple binding Pin
Brett Slaski1-Jul-04 5:54
Brett Slaski1-Jul-04 5:54 
GeneralRe: Question on simple binding Pin
Heath Stewart1-Jul-04 17:48
protectorHeath Stewart1-Jul-04 17:48 
GeneralRe: Question on simple binding Pin
Brett Slaski2-Jul-04 3:08
Brett Slaski2-Jul-04 3:08 
GeneralRe: Question on simple binding Pin
Heath Stewart2-Jul-04 3:40
protectorHeath Stewart2-Jul-04 3:40 
GeneralRe: Question on simple binding Pin
Brett Slaski2-Jul-04 9:25
Brett Slaski2-Jul-04 9:25 
GeneralOOP implemenation question Pin
mealnumberone30-Jun-04 2:27
mealnumberone30-Jun-04 2:27 
GeneralRe: OOP implemenation question Pin
Colin Angus Mackay30-Jun-04 3:15
Colin Angus Mackay30-Jun-04 3:15 
GeneralRe: OOP implemenation question Pin
mealnumberone30-Jun-04 7:13
mealnumberone30-Jun-04 7:13 
GeneralRe: OOP implemenation question Pin
Heath Stewart30-Jun-04 8:39
protectorHeath Stewart30-Jun-04 8:39 
GeneralMouseHover on toolbar button Pin
Member 114743230-Jun-04 1:52
Member 114743230-Jun-04 1:52 
GeneralRe: MouseHover on toolbar button Pin
Nick Parker30-Jun-04 3:06
protectorNick Parker30-Jun-04 3:06 
GeneralRe: MouseHover on toolbar button Pin
Heath Stewart30-Jun-04 3:55
protectorHeath Stewart30-Jun-04 3:55 
GeneralRe: MouseHover on toolbar button Pin
Nick Parker30-Jun-04 6:28
protectorNick Parker30-Jun-04 6:28 
GeneralRe: MouseHover on toolbar button Pin
Heath Stewart30-Jun-04 3:54
protectorHeath Stewart30-Jun-04 3:54 
Generalrefactoring plugin Pin
steven shingler30-Jun-04 1:40
steven shingler30-Jun-04 1:40 
GeneralRe: refactoring plugin Pin
Werdna30-Jun-04 5:49
Werdna30-Jun-04 5:49 
GeneralRe: refactoring plugin Pin
steven shingler30-Jun-04 5:55
steven shingler30-Jun-04 5:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.