Link to home
Start Free TrialLog in
Avatar of GRChandrashekar
GRChandrashekarFlag for India

asked on

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
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

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
Avatar of GRChandrashekar

ASKER

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.
Avatar of puru1981
puru1981

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.
Would you please explain this

insertAt method
sorry it is Insert Method
 
cmbbankerid.Items.Insert(0, "None");
        cmbbankerid.Items.Insert(datasourcebanker.Length, "All");
This line does not work
datasourcebanker.Length
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.
it is basically datasource which am using like  cmbbankerid.DataSource = datasourcebanker;

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

So what to write ?
ASKER CERTIFIED SOLUTION
Avatar of puru1981
puru1981

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
datasource banker is just an entity collection
which am using like
private readonly EntityCollection datasourcebanker =
            new EntityCollection(new BankerEntityFactory());
you can use count property for this.
How ? I just need to add an empty row with index 0