I have combobox bound to a sorted dataview of a strongly
typed datatable. After adding a new record to the
datatable, I would like to have that new record be
displayed in the textbox portion of the combobox. I have
tried the following to no avail:

myCombo.SelectedValue = newPrimaryKeyID
myCombo.Refresh

Any suggestions would be appreciated. Thanks.
JT

RE: Refreshing a ComboBox by v-yiy

v-yiy
Thu Sep 11 02:55:57 CDT 2003

Hi JT,
You may try using the CurrencyManager of your DataTable.
You can get the it by the the BindingContext property.
e.g.
CurrencyManager cm = BindingContext[dataTable1] as CurrencyManager;
then set the cm to the corresponding datarow.

If you have any questions on this issue, please let me know!

Thanks for using MSDN Newsgroup!


Best regards,

Ying-Shen Yu [MS]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "JT" <JTnospam@verizon.net>
| Sender: "JT" <JTnospam@verizon.net>
| Subject: Refreshing a ComboBox
| Date: Wed, 10 Sep 2003 10:37:45 -0700
| Lines: 11
| Message-ID: <011901c377c2$3ed91240$a401280a@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcN3wj7WlUQjvqeUSweRhHKPcz+/hg==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:52071
| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| I have combobox bound to a sorted dataview of a strongly
| typed datatable. After adding a new record to the
| datatable, I would like to have that new record be
| displayed in the textbox portion of the combobox. I have
| tried the following to no avail:
|
| myCombo.SelectedValue = newPrimaryKeyID
| myCombo.Refresh
|
| Any suggestions would be appreciated. Thanks.
| JT
|


RE: Refreshing a ComboBox by JT

JT
Mon Sep 15 07:52:02 CDT 2003

Thank you. Unfortunately, I cannot get this method to
work. Could you please be more specific as to exactly
how you would do this. Also, since the only control
bound to this datasource is a combobox, is the
currencymanager the way to go? Thanks.
JT
>-----Original Message-----
>Hi JT,
> You may try using the CurrencyManager of your
DataTable.
>You can get the it by the the BindingContext property.
>e.g.
>CurrencyManager cm = BindingContext[dataTable1] as
CurrencyManager;
>then set the cm to the corresponding datarow.
>
>If you have any questions on this issue, please let me
know!
>
>Thanks for using MSDN Newsgroup!
>
>
>Best regards,
>
>Ying-Shen Yu [MS]
>Microsoft Online Partner Support
>Get Secure! - www.microsoft.com/security
>
>This posting is provided "as is" with no warranties and
confers no rights.
>
>--------------------
>| Content-Class: urn:content-classes:message
>| From: "JT" <JTnospam@verizon.net>
>| Sender: "JT" <JTnospam@verizon.net>
>| Subject: Refreshing a ComboBox
>| Date: Wed, 10 Sep 2003 10:37:45 -0700
>| Lines: 11
>| Message-ID: <011901c377c2$3ed91240$a401280a@phx.gbl>
>| MIME-Version: 1.0
>| Content-Type: text/plain;
>| charset="iso-8859-1"
>| Content-Transfer-Encoding: 7bit
>| X-Newsreader: Microsoft CDO for Windows 2000
>| X-MimeOLE: Produced By Microsoft MimeOLE
V5.50.4910.0300
>| Thread-Index: AcN3wj7WlUQjvqeUSweRhHKPcz+/hg==
>| Newsgroups:
microsoft.public.dotnet.framework.windowsforms
>| Path: cpmsftngxa06.phx.gbl
>| Xref: cpmsftngxa06.phx.gbl
>microsoft.public.dotnet.framework.windowsforms:52071
>| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
>| X-Tomcat-NG:
microsoft.public.dotnet.framework.windowsforms
>|
>| I have combobox bound to a sorted dataview of a
strongly
>| typed datatable. After adding a new record to the
>| datatable, I would like to have that new record be
>| displayed in the textbox portion of the combobox. I
have
>| tried the following to no avail:
>|
>| myCombo.SelectedValue = newPrimaryKeyID
>| myCombo.Refresh
>|
>| Any suggestions would be appreciated. Thanks.
>| JT
>|
>
>.
>

RE: Refreshing a ComboBox by v-yiy

v-yiy
Tue Sep 16 07:21:25 CDT 2003

Hi JT,
This is the main part of my test code,
to run this code you need create an new c# Windows Application project.
add a datagrid, a combobox, and textbox on the form, all controls are using
their auto generated names.
add the code to corresponding event handlers.
<test code>
private void Form1_Load(object sender, System.EventArgs e)
{
DataTable dt = new DataTable();
//define a table
dt.Columns.Add("ID",typeof(int));
dt.Columns.Add("Name",typeof(string));
//fill the data
dt.Rows.Add(new object[]{1,"ABC"});
dt.Rows.Add(new object[]{2,"DEF"});
dt.Rows.Add(new object[]{3,"GHI"});

//set DataBinding
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "ID";
comboBox1.ValueMember = "ID";

textBox1.DataBindings.Add("Text",dt,"Name");

dataGrid1.DataSource = dt;
}

private void button1_Click(object sender, System.EventArgs e)
{
//Add a new record to your data table and set current to it.
DataTable dt = dataGrid1.DataSource as DataTable;
dt.Rows.Add(new object[]{4,"JKL"});
BindingContext[dt].Position = dt.Rows.Count - 1;
}
</test code>

Note: if your data table is in a data set, you must set the binding to
combobox as follows,
<code>
comboBox1.DataSource = dataSet11;//set data source to dataset
comboBox1.DisplayMember = "TableName.ID";
comboBox1.ValueMember = "TableName.Name";
</code>
and also a little change to get the CurrencyManager,
<code>
BindingContext[dataSet11,"TableName"].Postion =
dataSet11.Tables["TableName"].Count - 1;
</code>

Thanks! If you still have problem, please let me know.
I'll sent this sample to you.

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" shouldbe removed before
sending, Thanks!

--------------------
| Content-Class: urn:content-classes:message
| From: "JT" <JTnospam@verizon.net>
| Sender: "JT" <JTnospam@verizon.net>
| References: <011901c377c2$3ed91240$a401280a@phx.gbl>
<Fzz35oDeDHA.2240@cpmsftngxa06.phx.gbl>
| Subject: RE: Refreshing a ComboBox
| Date: Mon, 15 Sep 2003 05:52:02 -0700
| Lines: 73
| Message-ID: <07cc01c37b88$28d8ee60$a401280a@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcN7iCjY4Q4EkFLxQDumDhlSxuNxZw==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa07.phx.gbl
| Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.framework.windowsforms:52229
| NNTP-Posting-Host: tk2msftngxa12.phx.gbl 10.40.1.164
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Thank you. Unfortunately, I cannot get this method to
| work. Could you please be more specific as to exactly
| how you would do this. Also, since the only control
| bound to this datasource is a combobox, is the
| currencymanager the way to go? Thanks.
| JT
| >-----Original Message-----
| >Hi JT,
| > You may try using the CurrencyManager of your
| DataTable.
| >You can get the it by the the BindingContext property.
| >e.g.
| >CurrencyManager cm = BindingContext[dataTable1] as
| CurrencyManager;
| >then set the cm to the corresponding datarow.
| >
| >If you have any questions on this issue, please let me
| know!
| >
| >Thanks for using MSDN Newsgroup!
| >
| >
| >Best regards,
| >
| >Ying-Shen Yu [MS]
| >Microsoft Online Partner Support
| >Get Secure! - www.microsoft.com/security
| >
| >This posting is provided "as is" with no warranties and
| confers no rights.
| >
| >--------------------
| >| Content-Class: urn:content-classes:message
| >| From: "JT" <JTnospam@verizon.net>
| >| Sender: "JT" <JTnospam@verizon.net>
| >| Subject: Refreshing a ComboBox
| >| Date: Wed, 10 Sep 2003 10:37:45 -0700
| >| Lines: 11
| >| Message-ID: <011901c377c2$3ed91240$a401280a@phx.gbl>
| >| MIME-Version: 1.0
| >| Content-Type: text/plain;
| >| charset="iso-8859-1"
| >| Content-Transfer-Encoding: 7bit
| >| X-Newsreader: Microsoft CDO for Windows 2000
| >| X-MimeOLE: Produced By Microsoft MimeOLE
| V5.50.4910.0300
| >| Thread-Index: AcN3wj7WlUQjvqeUSweRhHKPcz+/hg==
| >| Newsgroups:
| microsoft.public.dotnet.framework.windowsforms
| >| Path: cpmsftngxa06.phx.gbl
| >| Xref: cpmsftngxa06.phx.gbl
| >microsoft.public.dotnet.framework.windowsforms:52071
| >| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
| >| X-Tomcat-NG:
| microsoft.public.dotnet.framework.windowsforms
| >|
| >| I have combobox bound to a sorted dataview of a
| strongly
| >| typed datatable. After adding a new record to the
| >| datatable, I would like to have that new record be
| >| displayed in the textbox portion of the combobox. I
| have
| >| tried the following to no avail:
| >|
| >| myCombo.SelectedValue = newPrimaryKeyID
| >| myCombo.Refresh
| >|
| >| Any suggestions would be appreciated. Thanks.
| >| JT
| >|
| >
| >.
| >
|


RE: Refreshing a ComboBox by JT

JT
Tue Sep 16 15:18:37 CDT 2003

Thank you very much for your response. I had tried
something similar, and just now tried the following:

myCombo.datasource = dataView
myCombo.DisplayMember = dataView(1)
myCombo.ValueMember = dataView(0)

where the dataView has my strongly typed dataset.datatable
as its Table and IS SORTED on dataView(1) - the name
field that is also the display member of the combobox.

I then run this code after saving a new record in my
strongly typed datatable:

BindingContext(dataView).Position = dataView.Count - 1

The problem, as you may have guessed, is that this
displays the last entry in my alphabetically SORTED
dataView - not the record I just added. I guess the
question is - how do I determine the new records Position
after it has been inserted into a SORTED dataview?

Thanks for any thoughts you can come up with on this one.
JT


>-----Original Message-----
>Hi JT,
> This is the main part of my test code,
>to run this code you need create an new c# Windows
Application project.
>add a datagrid, a combobox, and textbox on the form, all
controls are using
>their auto generated names.
>add the code to corresponding event handlers.
><test code>
>private void Form1_Load(object sender, System.EventArgs
e)
>{
> DataTable dt = new DataTable();
> //define a table
> dt.Columns.Add("ID",typeof(int));
> dt.Columns.Add("Name",typeof(string));
> //fill the data
> dt.Rows.Add(new object[]{1,"ABC"});
> dt.Rows.Add(new object[]{2,"DEF"});
> dt.Rows.Add(new object[]{3,"GHI"});
>
> //set DataBinding
> comboBox1.DataSource = dt;
> comboBox1.DisplayMember = "ID";
> comboBox1.ValueMember = "ID";
>
> textBox1.DataBindings.Add("Text",dt,"Name");
>
> dataGrid1.DataSource = dt;
>}
>
>private void button1_Click(object sender,
System.EventArgs e)
>{
> //Add a new record to your data table and set
current to it.
> DataTable dt = dataGrid1.DataSource as DataTable;
> dt.Rows.Add(new object[]{4,"JKL"});
> BindingContext[dt].Position = dt.Rows.Count - 1;
>}
></test code>
>
>Note: if your data table is in a data set, you must set
the binding to
>combobox as follows,
><code>
>comboBox1.DataSource = dataSet11;//set data source to
dataset
>comboBox1.DisplayMember = "TableName.ID";
>comboBox1.ValueMember = "TableName.Name";
></code>
>and also a little change to get the CurrencyManager,
><code>
>BindingContext[dataSet11,"TableName"].Postion =
>dataSet11.Tables["TableName"].Count - 1;
></code>
>
>Thanks! If you still have problem, please let me know.
>I'll sent this sample to you.
>
>Best regards,
>
>Ying-Shen Yu [MSFT]
>Microsoft Online Partner Support
>Get Secure! - www.microsoft.com/security
>
>This posting is provided "AS IS" with no warranties and
confers no rights.
>You should not reply this mail directly, "Online"
shouldbe removed before
>sending, Thanks!
>
>--------------------
>| Content-Class: urn:content-classes:message
>| From: "JT" <JTnospam@verizon.net>
>| Sender: "JT" <JTnospam@verizon.net>
>| References: <011901c377c2$3ed91240$a401280a@phx.gbl>
><Fzz35oDeDHA.2240@cpmsftngxa06.phx.gbl>
>| Subject: RE: Refreshing a ComboBox
>| Date: Mon, 15 Sep 2003 05:52:02 -0700
>| Lines: 73
>| Message-ID: <07cc01c37b88$28d8ee60$a401280a@phx.gbl>
>| MIME-Version: 1.0
>| Content-Type: text/plain;
>| charset="iso-8859-1"
>| Content-Transfer-Encoding: 7bit
>| X-Newsreader: Microsoft CDO for Windows 2000
>| X-MimeOLE: Produced By Microsoft MimeOLE
V5.50.4910.0300
>| Thread-Index: AcN7iCjY4Q4EkFLxQDumDhlSxuNxZw==
>| Newsgroups:
microsoft.public.dotnet.framework.windowsforms
>| Path: cpmsftngxa07.phx.gbl
>| Xref: cpmsftngxa07.phx.gbl
>microsoft.public.dotnet.framework.windowsforms:52229
>| NNTP-Posting-Host: tk2msftngxa12.phx.gbl 10.40.1.164
>| X-Tomcat-NG:
microsoft.public.dotnet.framework.windowsforms
>|
>| Thank you. Unfortunately, I cannot get this method to
>| work. Could you please be more specific as to exactly
>| how you would do this. Also, since the only control
>| bound to this datasource is a combobox, is the
>| currencymanager the way to go? Thanks.
>| JT
>| >-----Original Message-----
>| >Hi JT,
>| > You may try using the CurrencyManager of your
>| DataTable.
>| >You can get the it by the the BindingContext property.
>| >e.g.
>| >CurrencyManager cm = BindingContext[dataTable1] as
>| CurrencyManager;
>| >then set the cm to the corresponding datarow.
>| >
>| >If you have any questions on this issue, please let
me
>| know!
>| >
>| >Thanks for using MSDN Newsgroup!
>| >
>| >
>| >Best regards,
>| >
>| >Ying-Shen Yu [MS]
>| >Microsoft Online Partner Support
>| >Get Secure! - www.microsoft.com/security
>| >
>| >This posting is provided "as is" with no warranties
and
>| confers no rights.
>| >
>| >--------------------
>| >| Content-Class: urn:content-classes:message
>| >| From: "JT" <JTnospam@verizon.net>
>| >| Sender: "JT" <JTnospam@verizon.net>
>| >| Subject: Refreshing a ComboBox
>| >| Date: Wed, 10 Sep 2003 10:37:45 -0700
>| >| Lines: 11
>| >| Message-ID: <011901c377c2$3ed91240$a401280a@phx.gbl>
>| >| MIME-Version: 1.0
>| >| Content-Type: text/plain;
>| >| charset="iso-8859-1"
>| >| Content-Transfer-Encoding: 7bit
>| >| X-Newsreader: Microsoft CDO for Windows 2000
>| >| X-MimeOLE: Produced By Microsoft MimeOLE
>| V5.50.4910.0300
>| >| Thread-Index: AcN3wj7WlUQjvqeUSweRhHKPcz+/hg==
>| >| Newsgroups:
>| microsoft.public.dotnet.framework.windowsforms
>| >| Path: cpmsftngxa06.phx.gbl
>| >| Xref: cpmsftngxa06.phx.gbl
>| >microsoft.public.dotnet.framework.windowsforms:52071
>| >| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
>| >| X-Tomcat-NG:
>| microsoft.public.dotnet.framework.windowsforms
>| >|
>| >| I have combobox bound to a sorted dataview of a
>| strongly
>| >| typed datatable. After adding a new record to the
>| >| datatable, I would like to have that new record be
>| >| displayed in the textbox portion of the combobox.
I
>| have
>| >| tried the following to no avail:
>| >|
>| >| myCombo.SelectedValue = newPrimaryKeyID
>| >| myCombo.Refresh
>| >|
>| >| Any suggestions would be appreciated. Thanks.
>| >| JT
>| >|
>| >
>| >.
>| >
>|
>
>.
>

RE: Refreshing a ComboBox by JT

JT
Tue Sep 16 16:04:31 CDT 2003

Update - I also tried removing the design time sort from
my dataview, and then sorted it right after setting the
binding context position. This also resulted in getting
the last alphabetical entry, as I guess it now assumes
position count-1 after the sort. I know nothing about
this area, but is some type of Hash Table a consideration
here?
JT
>-----Original Message-----
>Thank you very much for your response. I had tried
>something similar, and just now tried the following:
>
>myCombo.datasource = dataView
>myCombo.DisplayMember = dataView(1)
>myCombo.ValueMember = dataView(0)
>
>where the dataView has my strongly typed dataset.datatable
>as its Table and IS SORTED on dataView(1) - the name
>field that is also the display member of the combobox.
>
>I then run this code after saving a new record in my
>strongly typed datatable:
>
>BindingContext(dataView).Position = dataView.Count - 1
>
>The problem, as you may have guessed, is that this
>displays the last entry in my alphabetically SORTED
>dataView - not the record I just added. I guess the
>question is - how do I determine the new records Position
>after it has been inserted into a SORTED dataview?
>
>Thanks for any thoughts you can come up with on this one.
>JT
>
>
>>-----Original Message-----
>>Hi JT,
>> This is the main part of my test code,
>>to run this code you need create an new c# Windows
>Application project.
>>add a datagrid, a combobox, and textbox on the form, all
>controls are using
>>their auto generated names.
>>add the code to corresponding event handlers.
>><test code>
>>private void Form1_Load(object sender, System.EventArgs
>e)
>>{
>> DataTable dt = new DataTable();
>> //define a table
>> dt.Columns.Add("ID",typeof(int));
>> dt.Columns.Add("Name",typeof(string));
>> //fill the data
>> dt.Rows.Add(new object[]{1,"ABC"});
>> dt.Rows.Add(new object[]{2,"DEF"});
>> dt.Rows.Add(new object[]{3,"GHI"});
>>
>> //set DataBinding
>> comboBox1.DataSource = dt;
>> comboBox1.DisplayMember = "ID";
>> comboBox1.ValueMember = "ID";
>>
>> textBox1.DataBindings.Add("Text",dt,"Name");
>>
>> dataGrid1.DataSource = dt;
>>}
>>
>>private void button1_Click(object sender,
>System.EventArgs e)
>>{
>> //Add a new record to your data table and set
>current to it.
>> DataTable dt = dataGrid1.DataSource as DataTable;
>> dt.Rows.Add(new object[]{4,"JKL"});
>> BindingContext[dt].Position = dt.Rows.Count - 1;
>>}
>></test code>
>>
>>Note: if your data table is in a data set, you must set
>the binding to
>>combobox as follows,
>><code>
>>comboBox1.DataSource = dataSet11;//set data source to
>dataset
>>comboBox1.DisplayMember = "TableName.ID";
>>comboBox1.ValueMember = "TableName.Name";
>></code>
>>and also a little change to get the CurrencyManager,
>><code>
>>BindingContext[dataSet11,"TableName"].Postion =
>>dataSet11.Tables["TableName"].Count - 1;
>></code>
>>
>>Thanks! If you still have problem, please let me know.
>>I'll sent this sample to you.
>>
>>Best regards,
>>
>>Ying-Shen Yu [MSFT]
>>Microsoft Online Partner Support
>>Get Secure! - www.microsoft.com/security
>>
>>This posting is provided "AS IS" with no warranties and
>confers no rights.
>>You should not reply this mail directly, "Online"
>shouldbe removed before
>>sending, Thanks!
>>
>>--------------------
>>| Content-Class: urn:content-classes:message
>>| From: "JT" <JTnospam@verizon.net>
>>| Sender: "JT" <JTnospam@verizon.net>
>>| References: <011901c377c2$3ed91240$a401280a@phx.gbl>
>><Fzz35oDeDHA.2240@cpmsftngxa06.phx.gbl>
>>| Subject: RE: Refreshing a ComboBox
>>| Date: Mon, 15 Sep 2003 05:52:02 -0700
>>| Lines: 73
>>| Message-ID: <07cc01c37b88$28d8ee60$a401280a@phx.gbl>
>>| MIME-Version: 1.0
>>| Content-Type: text/plain;
>>| charset="iso-8859-1"
>>| Content-Transfer-Encoding: 7bit
>>| X-Newsreader: Microsoft CDO for Windows 2000
>>| X-MimeOLE: Produced By Microsoft MimeOLE
>V5.50.4910.0300
>>| Thread-Index: AcN7iCjY4Q4EkFLxQDumDhlSxuNxZw==
>>| Newsgroups:
>microsoft.public.dotnet.framework.windowsforms
>>| Path: cpmsftngxa07.phx.gbl
>>| Xref: cpmsftngxa07.phx.gbl
>>microsoft.public.dotnet.framework.windowsforms:52229
>>| NNTP-Posting-Host: tk2msftngxa12.phx.gbl 10.40.1.164
>>| X-Tomcat-NG:
>microsoft.public.dotnet.framework.windowsforms
>>|
>>| Thank you. Unfortunately, I cannot get this method to
>>| work. Could you please be more specific as to exactly
>>| how you would do this. Also, since the only control
>>| bound to this datasource is a combobox, is the
>>| currencymanager the way to go? Thanks.
>>| JT
>>| >-----Original Message-----
>>| >Hi JT,
>>| > You may try using the CurrencyManager of your
>>| DataTable.
>>| >You can get the it by the the BindingContext property.
>>| >e.g.
>>| >CurrencyManager cm = BindingContext[dataTable1] as
>>| CurrencyManager;
>>| >then set the cm to the corresponding datarow.
>>| >
>>| >If you have any questions on this issue, please let
>me
>>| know!
>>| >
>>| >Thanks for using MSDN Newsgroup!
>>| >
>>| >
>>| >Best regards,
>>| >
>>| >Ying-Shen Yu [MS]
>>| >Microsoft Online Partner Support
>>| >Get Secure! - www.microsoft.com/security
>>| >
>>| >This posting is provided "as is" with no warranties
>and
>>| confers no rights.
>>| >
>>| >--------------------
>>| >| Content-Class: urn:content-classes:message
>>| >| From: "JT" <JTnospam@verizon.net>
>>| >| Sender: "JT" <JTnospam@verizon.net>
>>| >| Subject: Refreshing a ComboBox
>>| >| Date: Wed, 10 Sep 2003 10:37:45 -0700
>>| >| Lines: 11
>>| >| Message-ID: <011901c377c2$3ed91240$a401280a@phx.gbl>
>>| >| MIME-Version: 1.0
>>| >| Content-Type: text/plain;
>>| >| charset="iso-8859-1"
>>| >| Content-Transfer-Encoding: 7bit
>>| >| X-Newsreader: Microsoft CDO for Windows 2000
>>| >| X-MimeOLE: Produced By Microsoft MimeOLE
>>| V5.50.4910.0300
>>| >| Thread-Index: AcN3wj7WlUQjvqeUSweRhHKPcz+/hg==
>>| >| Newsgroups:
>>| microsoft.public.dotnet.framework.windowsforms
>>| >| Path: cpmsftngxa06.phx.gbl
>>| >| Xref: cpmsftngxa06.phx.gbl
>>| >microsoft.public.dotnet.framework.windowsforms:52071
>>| >| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
>>| >| X-Tomcat-NG:
>>| microsoft.public.dotnet.framework.windowsforms
>>| >|
>>| >| I have combobox bound to a sorted dataview of a
>>| strongly
>>| >| typed datatable. After adding a new record to the
>>| >| datatable, I would like to have that new record be
>>| >| displayed in the textbox portion of the combobox.
>I
>>| have
>>| >| tried the following to no avail:
>>| >|
>>| >| myCombo.SelectedValue = newPrimaryKeyID
>>| >| myCombo.Refresh
>>| >|
>>| >| Any suggestions would be appreciated. Thanks.
>>| >| JT
>>| >|
>>| >
>>| >.
>>| >
>>|
>>
>>.
>>
>.
>

RE: Refreshing a ComboBox by v-yiy

v-yiy
Wed Sep 17 09:45:01 CDT 2003

Hi JT,
You couldn't do sorting after set it's position, because sorting will
rearrange the data rows in you dataview, but the Position index Property
will still remain the previous value, it's by design.
As an possible work around , can you delay your sort to the event when
user fire ComboBox.DropDown event? For under this event the user is more
likely to change to another selection, or you may look for a more proper
event (maybe SelectedIndexChanged)

Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" shouldbe removed before
sending, Thanks!

--------------------
| Content-Class: urn:content-classes:message
| From: "JT" <JTnospam@verizon.net>
| Sender: "JT" <JTnospam@verizon.net>
| References: <011901c377c2$3ed91240$a401280a@phx.gbl>
<Fzz35oDeDHA.2240@cpmsftngxa06.phx.gbl>
<07cc01c37b88$28d8ee60$a401280a@phx.gbl>
<NOiFO0EfDHA.3192@cpmsftngxa07.phx.gbl>
<042201c37c8f$b6670c00$a301280a@phx.gbl>
| Subject: RE: Refreshing a ComboBox
| Date: Tue, 16 Sep 2003 14:04:31 -0700
| Lines: 217
| Message-ID: <04c301c37c96$1fa82e00$a301280a@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcN8lh+l8oI62D6TRIq/1K72XgI1ew==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa07.phx.gbl
| Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.framework.windowsforms:52374
| NNTP-Posting-Host: tk2msftngxa11.phx.gbl 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Update - I also tried removing the design time sort from
| my dataview, and then sorted it right after setting the
| binding context position. This also resulted in getting
| the last alphabetical entry, as I guess it now assumes
| position count-1 after the sort. I know nothing about
| this area, but is some type of Hash Table a consideration
| here?
| JT
| >-----Original Message-----
| >Thank you very much for your response. I had tried
| >something similar, and just now tried the following:
| >
| >myCombo.datasource = dataView
| >myCombo.DisplayMember = dataView(1)
| >myCombo.ValueMember = dataView(0)
| >
| >where the dataView has my strongly typed dataset.datatable
| >as its Table and IS SORTED on dataView(1) - the name
| >field that is also the display member of the combobox.
| >
| >I then run this code after saving a new record in my
| >strongly typed datatable:
| >
| >BindingContext(dataView).Position = dataView.Count - 1
| >
| >The problem, as you may have guessed, is that this
| >displays the last entry in my alphabetically SORTED
| >dataView - not the record I just added. I guess the
| >question is - how do I determine the new records Position
| >after it has been inserted into a SORTED dataview?
| >
| >Thanks for any thoughts you can come up with on this one.
| >JT
| >
| >
| >>-----Original Message-----
| >>Hi JT,
| >> This is the main part of my test code,
| >>to run this code you need create an new c# Windows
| >Application project.
| >>add a datagrid, a combobox, and textbox on the form, all
| >controls are using
| >>their auto generated names.
| >>add the code to corresponding event handlers.
| >><test code>
| >>private void Form1_Load(object sender, System.EventArgs
| >e)
| >>{
| >> DataTable dt = new DataTable();
| >> //define a table
| >> dt.Columns.Add("ID",typeof(int));
| >> dt.Columns.Add("Name",typeof(string));
| >> //fill the data
| >> dt.Rows.Add(new object[]{1,"ABC"});
| >> dt.Rows.Add(new object[]{2,"DEF"});
| >> dt.Rows.Add(new object[]{3,"GHI"});
| >>
| >> //set DataBinding
| >> comboBox1.DataSource = dt;
| >> comboBox1.DisplayMember = "ID";
| >> comboBox1.ValueMember = "ID";
| >>
| >> textBox1.DataBindings.Add("Text",dt,"Name");
| >>
| >> dataGrid1.DataSource = dt;
| >>}
| >>
| >>private void button1_Click(object sender,
| >System.EventArgs e)
| >>{
| >> //Add a new record to your data table and set
| >current to it.
| >> DataTable dt = dataGrid1.DataSource as DataTable;
| >> dt.Rows.Add(new object[]{4,"JKL"});
| >> BindingContext[dt].Position = dt.Rows.Count - 1;
| >>}
| >></test code>
| >>
| >>Note: if your data table is in a data set, you must set
| >the binding to
| >>combobox as follows,
| >><code>
| >>comboBox1.DataSource = dataSet11;//set data source to
| >dataset
| >>comboBox1.DisplayMember = "TableName.ID";
| >>comboBox1.ValueMember = "TableName.Name";
| >></code>
| >>and also a little change to get the CurrencyManager,
| >><code>
| >>BindingContext[dataSet11,"TableName"].Postion =
| >>dataSet11.Tables["TableName"].Count - 1;
| >></code>
| >>
| >>Thanks! If you still have problem, please let me know.
| >>I'll sent this sample to you.
| >>
| >>Best regards,
| >>
| >>Ying-Shen Yu [MSFT]
| >>Microsoft Online Partner Support
| >>Get Secure! - www.microsoft.com/security
| >>
| >>This posting is provided "AS IS" with no warranties and
| >confers no rights.
| >>You should not reply this mail directly, "Online"
| >shouldbe removed before
| >>sending, Thanks!
| >>
| >>--------------------
| >>| Content-Class: urn:content-classes:message
| >>| From: "JT" <JTnospam@verizon.net>
| >>| Sender: "JT" <JTnospam@verizon.net>
| >>| References: <011901c377c2$3ed91240$a401280a@phx.gbl>
| >><Fzz35oDeDHA.2240@cpmsftngxa06.phx.gbl>
| >>| Subject: RE: Refreshing a ComboBox
| >>| Date: Mon, 15 Sep 2003 05:52:02 -0700
| >>| Lines: 73
| >>| Message-ID: <07cc01c37b88$28d8ee60$a401280a@phx.gbl>
| >>| MIME-Version: 1.0
| >>| Content-Type: text/plain;
| >>| charset="iso-8859-1"
| >>| Content-Transfer-Encoding: 7bit
| >>| X-Newsreader: Microsoft CDO for Windows 2000
| >>| X-MimeOLE: Produced By Microsoft MimeOLE
| >V5.50.4910.0300
| >>| Thread-Index: AcN7iCjY4Q4EkFLxQDumDhlSxuNxZw==
| >>| Newsgroups:
| >microsoft.public.dotnet.framework.windowsforms
| >>| Path: cpmsftngxa07.phx.gbl
| >>| Xref: cpmsftngxa07.phx.gbl
| >>microsoft.public.dotnet.framework.windowsforms:52229
| >>| NNTP-Posting-Host: tk2msftngxa12.phx.gbl 10.40.1.164
| >>| X-Tomcat-NG:
| >microsoft.public.dotnet.framework.windowsforms
| >>|
| >>| Thank you. Unfortunately, I cannot get this method to
| >>| work. Could you please be more specific as to exactly
| >>| how you would do this. Also, since the only control
| >>| bound to this datasource is a combobox, is the
| >>| currencymanager the way to go? Thanks.
| >>| JT
| >>| >-----Original Message-----
| >>| >Hi JT,
| >>| > You may try using the CurrencyManager of your
| >>| DataTable.
| >>| >You can get the it by the the BindingContext property.
| >>| >e.g.
| >>| >CurrencyManager cm = BindingContext[dataTable1] as
| >>| CurrencyManager;
| >>| >then set the cm to the corresponding datarow.
| >>| >
| >>| >If you have any questions on this issue, please let
| >me
| >>| know!
| >>| >
| >>| >Thanks for using MSDN Newsgroup!
| >>| >
| >>| >
| >>| >Best regards,
| >>| >
| >>| >Ying-Shen Yu [MS]
| >>| >Microsoft Online Partner Support
| >>| >Get Secure! - www.microsoft.com/security
| >>| >
| >>| >This posting is provided "as is" with no warranties
| >and
| >>| confers no rights.
| >>| >
| >>| >--------------------
| >>| >| Content-Class: urn:content-classes:message
| >>| >| From: "JT" <JTnospam@verizon.net>
| >>| >| Sender: "JT" <JTnospam@verizon.net>
| >>| >| Subject: Refreshing a ComboBox
| >>| >| Date: Wed, 10 Sep 2003 10:37:45 -0700
| >>| >| Lines: 11
| >>| >| Message-ID: <011901c377c2$3ed91240$a401280a@phx.gbl>
| >>| >| MIME-Version: 1.0
| >>| >| Content-Type: text/plain;
| >>| >| charset="iso-8859-1"
| >>| >| Content-Transfer-Encoding: 7bit
| >>| >| X-Newsreader: Microsoft CDO for Windows 2000
| >>| >| X-MimeOLE: Produced By Microsoft MimeOLE
| >>| V5.50.4910.0300
| >>| >| Thread-Index: AcN3wj7WlUQjvqeUSweRhHKPcz+/hg==
| >>| >| Newsgroups:
| >>| microsoft.public.dotnet.framework.windowsforms
| >>| >| Path: cpmsftngxa06.phx.gbl
| >>| >| Xref: cpmsftngxa06.phx.gbl
| >>| >microsoft.public.dotnet.framework.windowsforms:52071
| >>| >| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
| >>| >| X-Tomcat-NG:
| >>| microsoft.public.dotnet.framework.windowsforms
| >>| >|
| >>| >| I have combobox bound to a sorted dataview of a
| >>| strongly
| >>| >| typed datatable. After adding a new record to the
| >>| >| datatable, I would like to have that new record be
| >>| >| displayed in the textbox portion of the combobox.
| >I
| >>| have
| >>| >| tried the following to no avail:
| >>| >|
| >>| >| myCombo.SelectedValue = newPrimaryKeyID
| >>| >| myCombo.Refresh
| >>| >|
| >>| >| Any suggestions would be appreciated. Thanks.
| >>| >| JT
| >>| >|
| >>| >
| >>| >.
| >>| >
| >>|
| >>
| >>.
| >>
| >.
| >
|


RE: Refreshing a ComboBox by JT

JT
Wed Sep 17 15:19:31 CDT 2003

Thanks. What I am doing is setting the dataview.sort to
a zero length string just prior to merging in my new
datarow. Then, on dropdown, I reset the sort as
desired. I presume there is no way of detecting a
datarow's position in a datatable that could be used to
resync the bindings. Thanks.
JT
>-----Original Message-----
>Hi JT,
> You couldn't do sorting after set it's position,
because sorting will
>rearrange the data rows in you dataview, but the
Position index Property
>will still remain the previous value, it's by design.
> As an possible work around , can you delay your
sort to the event when
>user fire ComboBox.DropDown event? For under this event
the user is more
>likely to change to another selection, or you may look
for a more proper
>event (maybe SelectedIndexChanged)
>
>Thanks!
>
>Best regards,
>
>Ying-Shen Yu [MSFT]
>Microsoft Online Partner Support
>Get Secure! - www.microsoft.com/security
>
>This posting is provided "AS IS" with no warranties and
confers no rights.
>You should not reply this mail directly, "Online"
shouldbe removed before
>sending, Thanks!
>
>--------------------
>| Content-Class: urn:content-classes:message
>| From: "JT" <JTnospam@verizon.net>
>| Sender: "JT" <JTnospam@verizon.net>
>| References: <011901c377c2$3ed91240$a401280a@phx.gbl>
><Fzz35oDeDHA.2240@cpmsftngxa06.phx.gbl>
><07cc01c37b88$28d8ee60$a401280a@phx.gbl>
><NOiFO0EfDHA.3192@cpmsftngxa07.phx.gbl>
><042201c37c8f$b6670c00$a301280a@phx.gbl>
>| Subject: RE: Refreshing a ComboBox
>| Date: Tue, 16 Sep 2003 14:04:31 -0700
>| Lines: 217
>| Message-ID: <04c301c37c96$1fa82e00$a301280a@phx.gbl>
>| MIME-Version: 1.0
>| Content-Type: text/plain;
>| charset="iso-8859-1"
>| Content-Transfer-Encoding: 7bit
>| X-Newsreader: Microsoft CDO for Windows 2000
>| X-MimeOLE: Produced By Microsoft MimeOLE
V5.50.4910.0300
>| Thread-Index: AcN8lh+l8oI62D6TRIq/1K72XgI1ew==
>| Newsgroups:
microsoft.public.dotnet.framework.windowsforms
>| Path: cpmsftngxa07.phx.gbl
>| Xref: cpmsftngxa07.phx.gbl
>microsoft.public.dotnet.framework.windowsforms:52374
>| NNTP-Posting-Host: tk2msftngxa11.phx.gbl 10.40.1.163
>| X-Tomcat-NG:
microsoft.public.dotnet.framework.windowsforms
>|
>| Update - I also tried removing the design time sort
from
>| my dataview, and then sorted it right after setting
the
>| binding context position. This also resulted in
getting
>| the last alphabetical entry, as I guess it now assumes
>| position count-1 after the sort. I know nothing about
>| this area, but is some type of Hash Table a
consideration
>| here?
>| JT
>| >-----Original Message-----
>| >Thank you very much for your response. I had tried
>| >something similar, and just now tried the following:
>| >
>| >myCombo.datasource = dataView
>| >myCombo.DisplayMember = dataView(1)
>| >myCombo.ValueMember = dataView(0)
>| >
>| >where the dataView has my strongly typed
dataset.datatable
>| >as its Table and IS SORTED on dataView(1) - the name
>| >field that is also the display member of the combobox.
>| >
>| >I then run this code after saving a new record in my
>| >strongly typed datatable:
>| >
>| >BindingContext(dataView).Position = dataView.Count - 1
>| >
>| >The problem, as you may have guessed, is that this
>| >displays the last entry in my alphabetically SORTED
>| >dataView - not the record I just added. I guess the
>| >question is - how do I determine the new records
Position
>| >after it has been inserted into a SORTED dataview?
>| >
>| >Thanks for any thoughts you can come up with on this
one.
>| >JT
>| >
>| >
>| >>-----Original Message-----
>| >>Hi JT,
>| >> This is the main part of my test code,
>| >>to run this code you need create an new c# Windows
>| >Application project.
>| >>add a datagrid, a combobox, and textbox on the form,
all
>| >controls are using
>| >>their auto generated names.
>| >>add the code to corresponding event handlers.
>| >><test code>
>| >>private void Form1_Load(object sender,
System.EventArgs
>| >e)
>| >>{
>| >> DataTable dt = new DataTable();
>| >> //define a table
>| >> dt.Columns.Add("ID",typeof(int));
>| >> dt.Columns.Add("Name",typeof(string));
>| >> //fill the data
>| >> dt.Rows.Add(new object[]{1,"ABC"});
>| >> dt.Rows.Add(new object[]{2,"DEF"});
>| >> dt.Rows.Add(new object[]{3,"GHI"});
>| >>
>| >> //set DataBinding
>| >> comboBox1.DataSource = dt;
>| >> comboBox1.DisplayMember = "ID";
>| >> comboBox1.ValueMember = "ID";
>| >>
>| >> textBox1.DataBindings.Add("Text",dt,"Name");
>| >>
>| >> dataGrid1.DataSource = dt;
>| >>}
>| >>
>| >>private void button1_Click(object sender,
>| >System.EventArgs e)
>| >>{
>| >> //Add a new record to your data table and set
>| >current to it.
>| >> DataTable dt = dataGrid1.DataSource as DataTable;
>| >> dt.Rows.Add(new object[]{4,"JKL"});
>| >> BindingContext[dt].Position = dt.Rows.Count - 1;
>| >>}
>| >></test code>
>| >>
>| >>Note: if your data table is in a data set, you must
set
>| >the binding to
>| >>combobox as follows,
>| >><code>
>| >>comboBox1.DataSource = dataSet11;//set data source
to
>| >dataset
>| >>comboBox1.DisplayMember = "TableName.ID";
>| >>comboBox1.ValueMember = "TableName.Name";
>| >></code>
>| >>and also a little change to get the CurrencyManager,
>| >><code>
>| >>BindingContext[dataSet11,"TableName"].Postion =
>| >>dataSet11.Tables["TableName"].Count - 1;
>| >></code>
>| >>
>| >>Thanks! If you still have problem, please let me
know.
>| >>I'll sent this sample to you.
>| >>
>| >>Best regards,
>| >>
>| >>Ying-Shen Yu [MSFT]
>| >>Microsoft Online Partner Support
>| >>Get Secure! - www.microsoft.com/security
>| >>
>| >>This posting is provided "AS IS" with no warranties
and
>| >confers no rights.
>| >>You should not reply this mail directly, "Online"
>| >shouldbe removed before
>| >>sending, Thanks!
>| >>
>| >>--------------------
>| >>| Content-Class: urn:content-classes:message
>| >>| From: "JT" <JTnospam@verizon.net>
>| >>| Sender: "JT" <JTnospam@verizon.net>
>| >>| References: <011901c377c2$3ed91240
$a401280a@phx.gbl>
>| >><Fzz35oDeDHA.2240@cpmsftngxa06.phx.gbl>
>| >>| Subject: RE: Refreshing a ComboBox
>| >>| Date: Mon, 15 Sep 2003 05:52:02 -0700
>| >>| Lines: 73
>| >>| Message-ID: <07cc01c37b88$28d8ee60
$a401280a@phx.gbl>
>| >>| MIME-Version: 1.0
>| >>| Content-Type: text/plain;
>| >>| charset="iso-8859-1"
>| >>| Content-Transfer-Encoding: 7bit
>| >>| X-Newsreader: Microsoft CDO for Windows 2000
>| >>| X-MimeOLE: Produced By Microsoft MimeOLE
>| >V5.50.4910.0300
>| >>| Thread-Index: AcN7iCjY4Q4EkFLxQDumDhlSxuNxZw==
>| >>| Newsgroups:
>| >microsoft.public.dotnet.framework.windowsforms
>| >>| Path: cpmsftngxa07.phx.gbl
>| >>| Xref: cpmsftngxa07.phx.gbl
>| >>microsoft.public.dotnet.framework.windowsforms:52229
>| >>| NNTP-Posting-Host: tk2msftngxa12.phx.gbl
10.40.1.164
>| >>| X-Tomcat-NG:
>| >microsoft.public.dotnet.framework.windowsforms
>| >>|
>| >>| Thank you. Unfortunately, I cannot get this
method to
>| >>| work. Could you please be more specific as to
exactly
>| >>| how you would do this. Also, since the only
control
>| >>| bound to this datasource is a combobox, is the
>| >>| currencymanager the way to go? Thanks.
>| >>| JT
>| >>| >-----Original Message-----
>| >>| >Hi JT,
>| >>| > You may try using the CurrencyManager of
your
>| >>| DataTable.
>| >>| >You can get the it by the the BindingContext
property.
>| >>| >e.g.
>| >>| >CurrencyManager cm = BindingContext[dataTable1]
as
>| >>| CurrencyManager;
>| >>| >then set the cm to the corresponding datarow.
>| >>| >
>| >>| >If you have any questions on this issue, please
let
>| >me
>| >>| know!
>| >>| >
>| >>| >Thanks for using MSDN Newsgroup!
>| >>| >
>| >>| >
>| >>| >Best regards,
>| >>| >
>| >>| >Ying-Shen Yu [MS]
>| >>| >Microsoft Online Partner Support
>| >>| >Get Secure! - www.microsoft.com/security
>| >>| >
>| >>| >This posting is provided "as is" with no
warranties
>| >and
>| >>| confers no rights.
>| >>| >
>| >>| >--------------------
>| >>| >| Content-Class: urn:content-classes:message
>| >>| >| From: "JT" <JTnospam@verizon.net>
>| >>| >| Sender: "JT" <JTnospam@verizon.net>
>| >>| >| Subject: Refreshing a ComboBox
>| >>| >| Date: Wed, 10 Sep 2003 10:37:45 -0700
>| >>| >| Lines: 11
>| >>| >| Message-ID: <011901c377c2$3ed91240
$a401280a@phx.gbl>
>| >>| >| MIME-Version: 1.0
>| >>| >| Content-Type: text/plain;
>| >>| >| charset="iso-8859-1"
>| >>| >| Content-Transfer-Encoding: 7bit
>| >>| >| X-Newsreader: Microsoft CDO for Windows 2000
>| >>| >| X-MimeOLE: Produced By Microsoft MimeOLE
>| >>| V5.50.4910.0300
>| >>| >| Thread-Index: AcN3wj7WlUQjvqeUSweRhHKPcz+/hg==
>| >>| >| Newsgroups:
>| >>| microsoft.public.dotnet.framework.windowsforms
>| >>| >| Path: cpmsftngxa06.phx.gbl
>| >>| >| Xref: cpmsftngxa06.phx.gbl
>| >>|
>microsoft.public.dotnet.framework.windowsforms:52071
>| >>| >| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
>| >>| >| X-Tomcat-NG:
>| >>| microsoft.public.dotnet.framework.windowsforms
>| >>| >|
>| >>| >| I have combobox bound to a sorted dataview of a
>| >>| strongly
>| >>| >| typed datatable. After adding a new record to
the
>| >>| >| datatable, I would like to have that new record
be
>| >>| >| displayed in the textbox portion of the
combobox.
>| >I
>| >>| have
>| >>| >| tried the following to no avail:
>| >>| >|
>| >>| >| myCombo.SelectedValue = newPrimaryKeyID
>| >>| >| myCombo.Refresh
>| >>| >|
>| >>| >| Any suggestions would be appreciated. Thanks.
>| >>| >| JT
>| >>| >|
>| >>| >
>| >>| >.
>| >>| >
>| >>|
>| >>
>| >>.
>| >>
>| >.
>| >
>|
>
>.
>