473,388 Members | 1,322 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How TO Set Default Value In Combobox

HI,

I am using combox, the values comes dynamically from database.
ex: combobox shows values such as category: food, clothes, watches...ect

now when the form loads i want to show ''ALL" as default category.
without entering "ALL" as values in database.

"ExecuteCommandReturnDataTable" is method defined in connection.cs file
i dont want to make any changes in it.

also my code look likes

Expand|Select|Wrap|Line Numbers
  1. MyConnection con = new MyConnection();
  2.                 string sql;
  3.                 sql = "select PlayerCatID, PlayerCatName from  
  4.                          tblcms_mst_PlayerCategory";
  5.                 DataTable dt;
  6.                 dt = (DataTable)con.ExecuteCommandReturnDataTable(sql);
  7.                 cmbPlayerCategory.DataSource = dt;
  8.                 cmbPlayerCategory.DisplayMember = "PlayerCatName";
  9.                 cmbPlayerCategory.ValueMember = "PlayerCatID";
  10.                 cmbPlayerCategory.Name = "PlayerCategoryName";
  11.                 con.disposeMe();
  12.  
Jun 2 '07 #1
1 1291
kenobewan
4,871 Expert 4TB
I believe that you can alter your datatable before using it as the datasource. HTH.
Jun 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Todd D. Levy | last post by:
I have a number of Drop Down Combo Boxes where users select a country; 99% of the time the selection will be "United States". I want to use VBA code in the New Record Event to populate this field...
7
by: NCrum | last post by:
I want to set the Default value of a Combobox for any changeable record and have got this working but it is totaly unsatisfactory see the code below I loop through the items in the Combo looking...
2
by: Keith | last post by:
I have populated (or created a collection) in a ComboBox. However - I would like to set a default value - when my form is first opened (for the ComboBox) - like "Select topic" However - when I...
6
by: dbuchanan | last post by:
Hello, Is this a bug? Is there some kind of work around? I want to add default values for a few columns in my datagridview I found the "DefaultValuesNeeded" event for the datagridview I...
0
by: yalanue | last post by:
I want to create a combobox with its displaymember populated from a datatable. But once I get it run, the default display member in the combobox is always the first row of the displaymember list....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.