Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

adding blank row to datasource

Hi,

I am populating combobox from two tables with following query

private void Fillcmbbankerid()
        {
            try
            {
                {
                    prefetchPathbanker.Add(BankerEntity.PrefetchPathBank);
                    bucketbanker.PredicateExpression.Add(BankerFields.Flag ==
                                                         StandardFlag.recordvalidflag);
                    adapterbanker.FetchEntityCollection(datasourcebanker, bucketbanker, 0,
                                                        new SortExpression(BankerFields.BankerId |
                                                                           SortOperator.Ascending),
                                                        prefetchPathbanker);
                    cmbbankerid.DataSource = datasourcebanker;
                    cmbbankerid.DisplayMember = "DESCRIPTION";
                    cmbbankerid.ValueMember = "BANKERID";
                    cmbbankerid.SelectedIndex = -1;
                }
            }
            catch (Exception ex)
            {
                GlobalErrorHandler.LogMessage(ex.Message + ex.StackTrace);
            }
            finally
            {
                adapterbanker.CloseConnection();
            }
        }

Output of query what I have written is SELECT   BANK.DESCRIPTION, BANKER.BANKER_ID
  FROM   BANKER, BANK
 WHERE   (BANK.BANK_ID = BANKER.BANK_ID) AND (BANKER.FLAG = 0)

Problem
Now the question is how to i add a blank row to this datasource. ?
Remember, I am using two tables here
0
GRChandrashekar
Asked:
GRChandrashekar
  • 8
  • 5
1 Solution
 
DhaestCommented:
Do you want an empty item added to the combobox or what exactly do you want ?

http://www.tek-tips.com/faqs.cfm?fid=5281
0
 
GRChandrashekarAuthor Commented:
Well I know how to add an empty Item

The problem is adding an empty item when I am loading combobox with relations from 2 tables as stated in my query under my question.
0
 
puru1981Commented:
it is possible to do but you need to use union for this. where you can write a select query which will return a single blank row.

but its better to use it this way because it will be scalable.

you can use combobox insertAt method to add an empty item because from the select query it would be not possible.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
GRChandrashekarAuthor Commented:
Would you please explain this

insertAt method
0
 
puru1981Commented:
sorry it is Insert Method
 
cmbbankerid.Items.Insert(0, "None");
        cmbbankerid.Items.Insert(datasourcebanker.Length, "All");
0
 
GRChandrashekarAuthor Commented:
This line does not work
datasourcebanker.Length
0
 
puru1981Commented:
i don't know the datatype of datasourcebanker so i written that. basic purpose was to insert the index. i thought it was an array so used Length. you can use appropriately.
0
 
GRChandrashekarAuthor Commented:
it is basically datasource which am using like  cmbbankerid.DataSource = datasourcebanker;

Not sure what i have to select instead of length
0
 
GRChandrashekarAuthor Commented:
I get option       datasourcebanker(int index,object item)

So what to write ?
0
 
puru1981Commented:
just remove this line. i have used it to insert a row at the end of the combobox.

alternatively, provide me the datatype of datasourcebanker.
0
 
GRChandrashekarAuthor Commented:
datasource banker is just an entity collection
0
 
GRChandrashekarAuthor Commented:
which am using like
private readonly EntityCollection datasourcebanker =
            new EntityCollection(new BankerEntityFactory());
0
 
puru1981Commented:
you can use count property for this.
0
 
GRChandrashekarAuthor Commented:
How ? I just need to add an empty row with index 0
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now