-----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" <
[email protected]>
| Sender: "JT" <
[email protected]>
| References: <
[email protected]>
<
[email protected]>
<
[email protected]>
<
[email protected]>
<
[email protected]>
| Subject: RE: Refreshing a ComboBox
| Date: Tue, 16 Sep 2003 14:04:31 -0700
| Lines: 217
| Message-ID: <
[email protected]>
| 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" <
[email protected]>
| >>| Sender: "JT" <
[email protected]>
| >>| References: <011901c377c2$3ed91240
[email protected]>
| >><
[email protected]>
| >>| Subject: RE: Refreshing a ComboBox
| >>| Date: Mon, 15 Sep 2003 05:52:02 -0700
| >>| Lines: 73
| >>| Message-ID: <07cc01c37b88$28d8ee60
[email protected]>
| >>| 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" <
[email protected]>
| >>| >| Sender: "JT" <
[email protected]>
| >>| >| Subject: Refreshing a ComboBox
| >>| >| Date: Wed, 10 Sep 2003 10:37:45 -0700
| >>| >| Lines: 11
| >>| >| Message-ID: <011901c377c2$3ed91240
[email protected]>
| >>| >| 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
| >>| >|
| >>| >
| >>| >.
| >>| >
| >>|
| >>
| >>.
| >>
| >.
| >
|
.