|
-
May 2nd, 2008, 02:09 PM
#1
Thread Starter
Lively Member
[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:
Dim wDtbl As New DataTable wDtbl.Columns.Add("id", GetType(Integer)) wDtbl.Columns.Add("exp", GetType(String)) Dim wdrwItem As DataRow wdrwItem = wDtbl.NewRow wdrwItem("id") = 0 wdrwItem("exp") = "Normal" wDtbl.Rows.Add(wdrwItem) wdrwItem = wDtbl.NewRow wdrwItem("id") = 1 wdrwItem("exp") = "Gr.1" wDtbl.Rows.Add(wdrwItem) ................................ comInvl.DisplayMember = "exp" comInvl.ValueMember = "id" 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.
-
May 2nd, 2008, 03:01 PM
#2
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.
-
May 2nd, 2008, 03:15 PM
#3
Thread Starter
Lively Member
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.
-
May 2nd, 2008, 03:51 PM
#4
Thread Starter
Lively Member
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:
wdset.Relations.Add(wrel_DP)
-
May 3rd, 2008, 01:10 AM
#5
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|