Paul Hartland
paul.hartland at googlemail.com
Thu Feb 12 09:41:29 CST 2015
Not quite, the combo box works perfect drops down the whole selection list,
if I select one I can show the ValueMember and DisplayMember and if I hard
code something like
Me.cmbRequestCodes.SelectedValue = 4 then the combo box displays the
correct text 'Incorrect Description'
I have a data table called 'tblPIPRequests' built as below:
cmdPIPRequests.Connection = pADOPIPConn
cmdPIPRequests.CommandText = "phPIP_SelectSingleRequest"
cmdPIPRequests.CommandType = CommandType.StoredProcedure
cmdPIPRequests.Parameters.AddWithValue("intRequestID", pLngPIPRequestID)
dapPIPRequests.SelectCommand = cmdPIPRequests
' Create an instance of a DataSet, and retrieve data from the Requests
table.
dapPIPRequests.FillSchema(datPIPRequests, SchemaType.Source, "PIPRequests")
dapPIPRequests.Fill(datPIPRequests, "PIPRequests")
tblPIPRequests = datPIPRequests.Tables("PIPRequests")
drCurrent = tblPIPRequests.Rows.Find(pLngPIPRequestID)
Now one of the fields that the data table brings back is RequestCode and I
need to assign this to the combo box to show the DisplayMember of the
corresponding RequestCode. I have tried
Me.cmbRequestCodes.SelectedValue = drCurrent!RequestCode
Which works, but not sure if this is the correct way to do all this, as I
say I am only just learning VB.net/Express.
Any help on this is greatly appreciated.
Also as you can see from the code where I create the data table
'tblPIPRequests' I use a stored procedure to bring back the results, the
form will allow the user to edit one or two of the fields via bound text
boxes, being bound like below:
Me.txtResolvedBy.DataBindings.Add("Text", tblPIPRequests, "ResolvedByName")
What I haven't been able to figure out is, once the user clicks the save
button on the form, how to update the data table 'tblPIPRequests' and the
SQL Datasource. Do I have to change from using a stored procedure to a
basic select statment for the table ? (as I read somewhere that UPDATE,
INSERT & DELETE's would automatically be created !!!!!)
Thanks again in advance for any help on this.
Paul
On 12 February 2015 at 14:28, Bill Benson <bensonforums at gmail.com> wrote:
> Paul, why not just set the bound columnwidths property such that the column
> you want has a width of 0? That is what I normally do if I take your
> meaning.
>
> On Thu, Feb 12, 2015 at 3:01 AM, Paul Hartland <
> paul.hartland at googlemail.com
> > wrote:
>
> > To all,
> >
> > I have only really developed in MS Access and Visual Basic 6.0....I am
> on a
> > learning curve at work where we have Visual Studio Express 2012 installed
> > on my machine. I have the following code to populate a combobox :
> >
> > Dim adtRequestCodes As New SqlDataAdapter()
> > Dim dsRequestCodes As New DataSet()
> > Try
> > Dim cmdPIPRequestCodes As New SqlCommand()
> > cmdPIPRequestCodes.Connection = pADOPIPConn
> > cmdPIPRequestCodes.CommandText = "phPIP_RequestCodes"
> > cmdPIPRequestCodes.CommandType = CommandType.StoredProcedure
> > adtRequestCodes.SelectCommand = cmdPIPRequestCodes
> > adtRequestCodes.Fill(dsRequestCodes)
> > adtRequestCodes.Dispose()
> > cmdPIPRequestCodes.Dispose()
> > Me.cmbRequestCodes.DataSource = dsRequestCodes.Tables(0)
> > Me.cmbRequestCodes.ValueMember = "ReasonID"
> > Me.cmbRequestCodes.DisplayMember = "ReasonCode"
> > Catch ex As Exception
> > MsgBox(ex.Message)
> > End Try
> >
> > This works as it populates the ComboBox. However I have datatable called
> > tblPIPRequests which I use to populate textboxes with data using
> something
> > like '
> >
> > Me.txtResolvedBy.DataBindings.Add("Text", tblPIPRequests,
> "ResolvedByName")
> > '. But can't figure out how to have the combobox show the value of
> > RequestCode from the datatable
> >
> > I.e. in the datatable 'tblPIPRequests' say the 'RequestCode' is 4 I need
> > the combobox to show the 'ReasonCode' associated with RequestCode 4 which
> > would be 'Incorrect Desription'
> >
> >
> > It may even be that I have set this all up wrong for what I need, I have
> > been googling here and there just to get where I am now.
> >
> > Any help GREATLY appreciated.
> >
> > --
> > Paul Hartland
> > paul.hartland at googlemail.com
> > --
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > http://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> >
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
--
Paul Hartland
paul.hartland at googlemail.com