Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Another databinding question

Options
  • 11-11-2004 4:55pm
    #1
    Registered Users Posts: 7,468 ✭✭✭


    Can I specify multiple fields for a bound Combobox's DisplayMember property?

    For example I wan't the display member to be Employee.SecondName and Employee.Firstname with a comma in between i.e. 'Wayne, Bruce'. Now, I know I can achieve this within the SQL but I want to know if I can do it this way too.

    Oh yeah, it's .Net.


Comments

  • Closed Accounts Posts: 25 maxcherry


    Ok dude

    In SQL Server - do this to return Fred,Reilly in field called name
    select Firstname + "," + SecondName name
    from users

    Don't know a whole pile about .NET but if your object returns
    SecondName and Firstname. Then do something like this
    String name = "";

    name = Employee.SecondName + "," + Employee.Firstname


  • Registered Users Posts: 2,758 ✭✭✭Peace


    Don't know about bog standard .Net controls but obviously it can be done becuase resellers sell controls that can do this....

    They are called Janus Controls.


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Thanks Peace, we're actually using some Janus controls but this is a plain old Combobox. I'll play around and see what I come up with.

    And thank you Maxcherry but ...
    Evil Phil wrote:
    Now, I know I can achieve this within the SQL but I want to know if I can do it this way too.

    I'm afraid I didn't ask you how I would populate a variable either.


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Evil Phil wrote:
    Can I specify multiple fields for a bound Combobox's DisplayMember property?

    Nope.

    There are, however, a multitude of multi-column-combo controls about. I think there's even some sample-code on places like codeproject to do exactly this.
    For example I wan't the display member to be Employee.SecondName and Employee.Firstname with a comma in between i.e. 'Wayne, Bruce'. Now, I know I can achieve this within the SQL but I want to know if I can do it this way too.
    If you want "Wayne, Bruce", then do it in the SQL, or in the dataTable (or business object) or somewhere before you get to the combo.

    If you want something where the "popup list" of the combo is more like a ListView (each surname in column0, each firstName in column1, and so on) then go check for multi-column-bindable controls. Janus, DevComponents, and Infragistics all do them that I know of....but you'll probably find more in the control library on gotdotnet if you check...or go to codeproject and see if someone has an example w. source for you.

    jc


  • Registered Users Posts: 2,758 ✭✭✭Peace


    If you have a Janus dev license how come you don't use the Janus drop down...

    Personally, i get around it the looooong way. I use collections to display/populate some dropdowns and on the click i just take the index of the combo list and it corresponds to the index of the collection... which in turn gives me all the properties i stored in my object. So essentially i'm not really binding so essentially i'm not answering your question. Sorry!


  • Advertisement
  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    In the SQL it is then, thats the easiest and I don't want to use up a dev license when I don't need too. I just thought it would be a cool feature, apparently Janus did too.

    I'll add that this databinding thing is a bit of a headache.


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Evil Phil wrote:
    I'll add that this databinding thing is a bit of a headache.

    I gave up on most data-binding as a bad job a long time ago.

    Ultimately, I find it involves as much code as a non-data-bound solution, especially once you start looking at multi-tier development with concurrency issues and the rest of it.....so I don't really find much benefit in it.

    I dunno...MS push the whole databinding thing, DataTables etc. massively, but then I go to TechEd and the advanced classes were all looking at how to optimise your DataReader access, etc. I pick up programming books, and if they are somewhere beyond "beginner" level, they tend to focus on techniques which have no place in the DB <-> DataTable <-> UI model which is what MS are pushing.

    Anyway...thats probably a topic for another day. I should get back to work....

    jc


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Oh...Phil...while I think of it....here's a neat trick you can do...

    Add *two* combo boxes to the same form. Bind them both to the same data-table....one to the surname, one to the firstname (for example). Select info in *either*, and the other will auto-select the appropriate field on the same record.

    While not hugely useful with FirstName/Surname, we had a situation recently where there was a Name/Code pair. Some users knew, and used, quite a lot of codes. Everyone used Names when they didn't know the code. Two combo's set up as described (with autosort and autocomplete coded in by hand) - one bound to the Code property, one to the Name property (was using an IList of "Business objects" as the source), and they could have both codes and names available, sorted, and *linked*.

    Worked a treat.

    jc


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Personally I shy away from it myself. I've been taken on to help a company meet a deadline - they're using strongly typed datasets with bound controls. We're now running into solutions which require a lot of logic and the binding seems to be rather constrictive.


Advertisement