-
Nov 14th, 2019, 09:19 AM
#1
Thread Starter
Junior Member
[RESOLVED] How to Sort Data Bound Combobox
Hi Guys!,
i am having this issue "ComboBox that has a DataSource set cannot be sorted. Sort the data using the underlying data model." is there a way to sort out data bound items?
i have been researching as well and found this on google
SiteBindingSource.DataSource = myDataTable <---- i can't find how to do myDataTable
SiteBindingSource.Sort = "SomeColumn" <----- changed this to "[Site Name]"
Combobox1.DataSource = SiteBindingSource
but i can't seem to make this work. i hope that somebody can help me on this
-
Nov 14th, 2019, 05:45 PM
#2
Re: How to Sort Data Bound Combobox
Show us the code that you currently have to populate your ComboBox.
-
Nov 15th, 2019, 03:11 AM
#3
Thread Starter
Junior Member
Re: How to Sort Data Bound Combobox
there's no codes to populate my combobox. i directly used the combobox properties and bind the items.
Update: i have found a work around but there will be a lot of work for me. i will have to change my column format directly from database because i am currently using "TEXT" and i need to change it to "VARCHAR(MAX)" for me to be able to sort it using properties from the combobox.
-
Nov 15th, 2019, 01:42 PM
#4
Re: How to Sort Data Bound Combobox
If your using a BindingSource as the Datasource for the Combobox then all you have to do is sort the bindingsource. In the form Load event yourBindingsource.Sort = "itemsFieldName"
-
Nov 15th, 2019, 02:11 PM
#5
Re: How to Sort Data Bound Combobox
It looks like that's what he was trying to do here:
SiteBindingSource.Sort = "SomeColumn"
But, if the type was Text... it may not have been sorting right since text is a "special" type and isn't treated the same as string (varchar).
-tg
-
Nov 15th, 2019, 02:35 PM
#6
Re: How to Sort Data Bound Combobox
Originally Posted by techgnome
It looks like that's what he was trying to do here:
SiteBindingSource.Sort = "SomeColumn"
But, if the type was Text... it may not have been sorting right since text is a "special" type and isn't treated the same as string (varchar).
-tg
Never used a Text data type field in Sql Server, Text was the string data type in Access. What's so special about the Text data type in Sql Server which makes it sort differently?
-
Nov 15th, 2019, 03:01 PM
#7
Re: How to Sort Data Bound Combobox
It's a form of BLOB. In some circles it would be called a CLOB.
-tg
-
Nov 15th, 2019, 06:17 PM
#8
Re: How to Sort Data Bound Combobox
Sounds like it's not the best data type to use. Read this in MS Docs,
IMPORTANT! ntext, text, and image data types will be removed in a future version of SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.
-
Nov 15th, 2019, 08:02 PM
#9
Re: How to Sort Data Bound Combobox
Originally Posted by wes4dbt
Sounds like it's not the best data type to use. Read this in MS Docs,
Those data types have been obsolete for at least a decade now - probably significantly more. Anyone who is using them for a new database is making a bad decision and almost certainly hasn't done enough reading.
Originally Posted by ahmish
i have found a work around but there will be a lot of work for me. i will have to change my column format directly from database because i am currently using "TEXT" and i need to change it to "VARCHAR(MAX)" for me to be able to sort it using properties from the combobox.
That's not really a workaround. Your issue only exists because you used the wrong data type in the first place so this is the correct way to make the problem go away so no solution is required.
It concerns me that you're considering using varchar(max) though. If you are displaying these values in a ComboBox and sorting them, exactly how long do you expect them to be? Even 100 characters would be lot to display in a ComboBox. There's no way that a database column intended to contain values for display in a drop-down list needs to be varchar(max). Decide on a sensible maximum length for those values and specify that in the column definition. Start thinking a bit about your database schema.
-
Nov 16th, 2019, 02:16 AM
#10
Thread Starter
Junior Member
Re: How to Sort Data Bound Combobox
Originally Posted by jmcilhinney
Those data types have been obsolete for at least a decade now - probably significantly more. Anyone who is using them for a new database is making a bad decision and almost certainly hasn't done enough reading.
That's not really a workaround. Your issue only exists because you used the wrong data type in the first place so this is the correct way to make the problem go away so no solution is required.
It concerns me that you're considering using varchar(max) though. If you are displaying these values in a ComboBox and sorting them, exactly how long do you expect them to be? Even 100 characters would be lot to display in a ComboBox. There's no way that a database column intended to contain values for display in a drop-down list needs to be varchar(max). Decide on a sensible maximum length for those values and specify that in the column definition. Start thinking a bit about your database schema.
thanks for the advise. i am new in coding and sql database with zero to maybe 5% knowledge. i am learning coding and sql database thru google only and learned for the last 3 months. i have a database columns which are mostly set as "TEXT" which i know now that is obsolete. i am now planning to migrate my database columns from "TEXT" to "Varchar" my concern here is i have a lot of columns with different functionality. i am sure that i need to use "varchar(max)" for atleast 2 columns. then i have columns that has minimum 50 characters and up to unknown characters depending on the site name. i will be checking the different types of tables.
is it safe to say that
INT - will be used for numbers
Varchar - for text
what about?
Nchar?
-
Nov 16th, 2019, 02:34 AM
#11
Re: How to Sort Data Bound Combobox
Originally Posted by ahmish
what about?
Nchar?
You don't need to ask us questions like that. You just need to read the relevant documentation and decide which description matches the type of data that you want to store. If you don't know what data type to use then you either don't understand the data types - in which case you should be reading up on the data types - or you don't understand your data.
char: fixed-length, single-byte
nchar: fixed-length, multi-byte
varchar: variable-length, single-byte
nvarchar: variable-length, multi-byte
You only have to ask yourself two question about your text data and the answers determine which data type to use. Although you can, it is rare that you would use a fixed-length data type for variable-length data because any value that is shorter will be padded with spaces and it's then up to you to remove them every time you retrieve the data. I generally only use fixed-length data types when the data is genuinely fixed-length, e.g. codes for US states. I think that fixed-length may actually be more efficient even if the data isn't always the same size, as long as the variation as small.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|