Results 1 to 5 of 5

Thread: [RESOLVED] [2008] Binding combobox question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Location
    Constanta,Romania
    Posts
    71

    Resolved [RESOLVED] [2008] Binding combobox question

    Hi !
    I have a table

    table1
    id (numeric)
    ...
    id_invalid (numeric)
    ......

    Field id_invalid could have 3 values
    0 - Normal
    1 -Gr.1
    2 -Gr.2
    This field in no FK,I have no table defined for these values,I use one combobox to select them,combo is bound this way to a temporary source :
    vb.net Code:
    1. Dim wDtbl As New DataTable
    2.         wDtbl.Columns.Add("id", GetType(Integer))
    3.         wDtbl.Columns.Add("exp", GetType(String))
    4.         Dim wdrwItem As DataRow
    5.         wdrwItem = wDtbl.NewRow
    6.         wdrwItem("id") = 0
    7.         wdrwItem("exp") = "Normal"
    8.         wDtbl.Rows.Add(wdrwItem)
    9.         wdrwItem = wDtbl.NewRow
    10.         wdrwItem("id") = 1
    11.         wdrwItem("exp") = "Gr.1"
    12.         wDtbl.Rows.Add(wdrwItem)
    13. ................................
    14.         comInvl.DisplayMember = "exp"
    15.         comInvl.ValueMember = "id"
    16.         comInvl.DataSource = wDtbl
    I get selected id using SelectedValue and write it to id_invalid field in table1

    My problem is : can I bind my combobox to display exp from wDtbl when I navigate into table1 ?

    Thanks !
    Last edited by ionut_y; May 2nd, 2008 at 02:13 PM.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] Binding combobox question

    What is the context here in which you will be 'navigating' to table1?

    You have set your DisplayMember and ValueMember properties and bound it to your wDtbl. How will you be 'getting' table1 in your code; I am assuming you want to have it select the value corresponding to the current row or record that you are viewing on the form.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Location
    Constanta,Romania
    Posts
    71

    Re: [2008] Binding combobox question

    Thanks mendhak .
    I think I found something that could solve my problem
    http://www.vbforums.com/showthread.p...bobox+relation
    I'll navigate using bindingnavigator control,table1 I'll get it into another datatable,now I'll try to use one relation as in the link above
    Last edited by ionut_y; May 2nd, 2008 at 04:02 PM.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Location
    Constanta,Romania
    Posts
    71

    Re: [2008] Binding combobox question

    There is a problem,my child table has rows even parent is empty,I got this error :

    "This constraint cannot be enabled as not all values have corresponding parent values"
    on this line :
    vb.net Code:
    1. wdset.Relations.Add(wrel_DP)

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Location
    Constanta,Romania
    Posts
    71

    Re: [2008] Binding combobox question

    I've done this way,I think is not the best solution :

    Dim wrel_DP As New DataRelation("Relat_gr", _
    wDts.Tables(0).Columns("id_invalid"), wDts.Tables(1).Columns("id"), False)

    I fount there : http://codesample.wordpress.com/2006...parent-values/

    "By default, when you create a relationship, it enforces foreign key constraints, by setting to false, you are telling it that you dont want to enforce the relationship."

    This way have no error but when I add a new value my combo shows only values from relationship so,when I press "add" or "modify" button I bind my combo to wDtbl,and after "save" or "cancel" I bind to relationship

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width