I can't sort my combo box. Please Help!

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When I try to sort my combo box I get the following error.

"Cannot sort a ComboBox that has a DataSource set. Sort the data using the
underlying data model."

--------------------------------THe code is given below.
String strSQL;

strSQL = "SELECT .......... WHERE C.Client = '" +
this.cboClient.SelectedValue + "' ";
userTable = manager.GetDataTable(strSQL,"userList");

cmbUserList.DataSource = userTable;
cmbUserList.DisplayMember = "FollowUpPerson";
cmbUserList.ValueMember = "FollowUpPerson";

cmbUserList.SelectedIndex = -1;
cmbUserList.Sorted = true;
------------------------------------------------
I do really appreciate any ideas or sugessions.

Thanks

raj
 
Raj,
The combobox will not fill if it has 'sorted' preselected in the design
process.

--------------------
Thread-Topic: I can't sort my combo box. Please Help!
thread-index: AcS/xvw8xLfcJGSzQJKvGzE1Rk/XNQ==
X-WBNR-Posting-Host: 203.28.214.209
From: =?Utf-8?B?cmFq?= <[email protected]>
Subject: I can't sort my combo box. Please Help!
Date: Sun, 31 Oct 2004 19:58:02 -0800
Lines: 24
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.general:150745
X-Tomcat-NG: microsoft.public.dotnet.general

When I try to sort my combo box I get the following error.

"Cannot sort a ComboBox that has a DataSource set. Sort the data using the
underlying data model."

--------------------------------THe code is given below.
String strSQL;

strSQL = "SELECT .......... WHERE C.Client = '" +
this.cboClient.SelectedValue + "' ";
userTable = manager.GetDataTable(strSQL,"userList");

cmbUserList.DataSource = userTable;
cmbUserList.DisplayMember = "FollowUpPerson";
cmbUserList.ValueMember = "FollowUpPerson";

cmbUserList.SelectedIndex = -1;
cmbUserList.Sorted = true;
------------------------------------------------
I do really appreciate any ideas or sugessions.

Thanks

raj

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fprq2\fcharset0
MS Sans Serif;}{\f1\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\f0\fs20 Cheers,\par
\par
johnKn [MS-SDK]\par
\par
\par
\par
-Please do not send email directly to this alias. This alias is for \par
newsgroup purposes only\par
\par
-This posting is provided "AS IS" with no warranties, and confers no
rights.\par
\par
-To provide additional feedback about your community experience please send
\par
e-mail to: (e-mail address removed)\par
\f1\par
}
 
Hi John Kn
No. the combobox field is not preselected. It is setted to 'FALSE'.
U'r correct it will not get populated if I selected to 'TRUE'.
But my combo box is get populated (As it SORT's seleted to 'FALSE') but I
can't sort at the moment. Do u have any suggestions? I'm trying to explicitly
code as 'cmbUserList.Sorted = true;' This will crashes my aplication with
error message.

Thanks
raj

John Kn said:
Raj,
The combobox will not fill if it has 'sorted' preselected in the design
process.

--------------------
Thread-Topic: I can't sort my combo box. Please Help!
thread-index: AcS/xvw8xLfcJGSzQJKvGzE1Rk/XNQ==
X-WBNR-Posting-Host: 203.28.214.209
From: =?Utf-8?B?cmFq?= <[email protected]>
Subject: I can't sort my combo box. Please Help!
Date: Sun, 31 Oct 2004 19:58:02 -0800
Lines: 24
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.general:150745
X-Tomcat-NG: microsoft.public.dotnet.general

When I try to sort my combo box I get the following error.

"Cannot sort a ComboBox that has a DataSource set. Sort the data using the
underlying data model."

--------------------------------THe code is given below.
String strSQL;

strSQL = "SELECT .......... WHERE C.Client = '" +
this.cboClient.SelectedValue + "' ";
userTable = manager.GetDataTable(strSQL,"userList");

cmbUserList.DataSource = userTable;
cmbUserList.DisplayMember = "FollowUpPerson";
cmbUserList.ValueMember = "FollowUpPerson";

cmbUserList.SelectedIndex = -1;
cmbUserList.Sorted = true;
------------------------------------------------
I do really appreciate any ideas or sugessions.

Thanks

raj

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fprq2\fcharset0
MS Sans Serif;}{\f1\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\f0\fs20 Cheers,\par
\par
johnKn [MS-SDK]\par
\par
\par
\par
-Please do not send email directly to this alias. This alias is for \par
newsgroup purposes only\par
\par
-This posting is provided "AS IS" with no warranties, and confers no
rights.\par
\par
-To provide additional feedback about your community experience please send
\par
e-mail to: (e-mail address removed)\par
\f1\par
}
 
Raj,

As the message tells, do you have when you use the datasource have to use a
sorted datasource, what is very easy to do.

Typed here so watch typos

DataView dv = new DataView(userTable);
dv.Sort = "FollowUpPerson";
cmbUserList.DataSource = dv;
I hope this helps?

Cor
 
raj said:
When I try to sort my combo box I get the following error.

"Cannot sort a ComboBox that has a DataSource set. Sort the data using the
underlying data model."

--------------------------------THe code is given below.
String strSQL;

strSQL = "SELECT .......... WHERE C.Client = '" +
this.cboClient.SelectedValue + "' ";
userTable = manager.GetDataTable(strSQL,"userList");

cmbUserList.DataSource = userTable;
cmbUserList.DisplayMember = "FollowUpPerson";
cmbUserList.ValueMember = "FollowUpPerson";

cmbUserList.SelectedIndex = -1;
cmbUserList.Sorted = true;
------------------------------------------------
I do really appreciate any ideas or sugessions.

Thanks

raj

Why not simply sort in the SQL query (order by FolowUpPerson)?

Rinze
 
You can also just sort on the .DefaultView property of the datatable,
instead of creating a new dataview object.
 
Hi
It works now.
I would like to thanks John, Cor Ligthert. Patrick and C-Serveces Holland,
for assisting me to solve this problem. Once again, many thanks.

Cheers

raj
 
Back
Top