Groups | Blog | Home
all groups > dotnet general > october 2004 >

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


raj
10/31/2004 7:58:02 PM
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
10/31/2004 9:13:01 PM
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

[quoted text, click to view]
johnknox NO[at]SPAM online.microsoft.com
11/1/2004 4:44:02 AM
Raj,
The combobox will not fill if it has 'sorted' preselected in the design
process.

--------------------
[quoted text, click to view]

{\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: sdkcomm@microsoft.com\par
\f1\par
}
Cor Ligthert
11/1/2004 8:19:35 AM
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;
[quoted text, click to view]

I hope this helps?

Cor

C-Services Holland b.v.
11/1/2004 11:25:00 AM
[quoted text, click to view]

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

Patrick
11/1/2004 5:02:51 PM

You can also just sort on the .DefaultView property of the datatable,
instead of creating a new dataview object.

[quoted text, click to view]

raj
11/1/2004 5:04:02 PM
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


[quoted text, click to view]
AddThis Social Bookmark Button