Databound label text property

Pace

Well-known member
Joined
Sep 2, 2005
Messages
90
Location
Manchester UK! :)
Programming Experience
1-3
Databound label text property (RESOLVED)

[FONT=Verdana, Geneva, Arial, Sans-serif]Hi, [/FONT]
[FONT=Verdana, Geneva, Arial, Sans-serif]I have a form with a combo box... I have a label that is bound to a column that displays info based on whats selected in the combo. [/FONT]
[FONT=Verdana, Geneva, Arial, Sans-serif]It looks fine when I first load the form. When I change the index of the CBO the text of the label stays the same. I know I need to write code to do this in the SelectedIndexChanged event of the CBO but im struggling. [/FONT]
[FONT=Verdana, Geneva, Arial, Sans-serif]Can someone tell me how once the index is changed in the CBO, I can get the label's text property to change appropriately to that of the value it should be?[/FONT]

[FONT=Verdana, Geneva, Arial, Sans-serif]Thanks![/FONT]
[FONT=Verdana, Geneva, Arial, Sans-serif]Pace[/FONT]
 
Last edited:
Also, the DataSet serves no purpose in your code. It's like creating an array to hold one Integer. You should just create a DataTable and Fill that.
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] da [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff] New[/COLOR][/SIZE][SIZE=2] OleDb.OleDbDataAdapter(strSQL, strCnn)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] dtProduct [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff] New[/COLOR][/SIZE] DataTable

[SIZE=2]da.Fill(dtProduct[/SIZE])
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].BindingSource1.DataSource = dtProduct[/SIZE]
 
Hi guys,

Thanks for your help!

Im totally sorry I wasn't understanding properly!

I haddnt been sleeping properly lately and therefore ive had a lot of mind blank...

Anyway im refreshed, and here is my now working code if anyone is having this problem;

VB.NET:
PrivateSub formDirectReceipt_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
Dim strSQL AsString
Dim strCnn AsNew SqlClient.SqlConnection(My.Settings.cnnSQL)
strSQL = "SELECT Product.[Product Code], Product.[Short Description], Product.Cost, Product.ProductionGroup " & _
"FROM Product " & _
"WHERE Product.ProductionGroup LIKE @cellVar"
Dim cmd AsNew SqlClient.SqlCommand(strSQL, strCnn)
Dim pr AsNew SqlClient.SqlParameter
pr.ParameterName = "@cellVar"
pr.Value = cellVar
cmd.Parameters.Add(pr)
Dim da AsNew SqlClient.SqlDataAdapter(cmd)
Dim bs AsNew BindingSource
Dim dsStockReceipt AsNew DataSet
da.Fill(dsStockReceipt, "Product")
bs.DataSource = dsStockReceipt
bs.DataMember = "Product"
Me.cboReceiptProduct.DisplayMember = "Product Code"
Me.cboReceiptProduct.DataSource = bs
Me.txDesc.DataBindings.Add("Text", bs, "Short Description")
Me.txCost.DataBindings.Add("Text", bs, "Cost")
Me.txPrdGrp.DataBindings.Add("Text", bs, "ProductionGroup")
EndSub

Once again thanks for your help and I apologise for the frustration caused...
 
Back
Top