Potato K

Ok, I have a super simple form that works, but not how I want it to...

My form has 1 combobox, 1 label, and 1 button.

I have a datasource, tableadapter, and a bindingsource.

The database has 3 fields in 1 table. ID, Name, URL

ID is not displayed on the form, the combobox is binded to Name, and the label is binded to URL.

on btn1 click

call shell("internetexplorer path " & label1.text, 1)

All works well and good. However, I dont want to have to show the URL... now, the ghetto work around is to make the label1 font color the same as the form back ground color, and that works... but, I'd like to know the 'right' way to do it.

I need to know how to dim url as string = url colum of the selected row basicly.

Hopefully that makes sense, and I apologize if that's a really noobish question.


Thanks in advance for any help.




Re: Visual Basic Express Edition How to create a string from a field of the selected row

spotty

I would assume you want to just access the bindingsource current record directly

http://msdn2.microsoft.com/en-us/library/system.windows.forms.bindingsource.current(VS.80).aspx

This will allow you to read the items of the current record which you are binding to.

Example

Dim dr As DataRow = Me.BindingSource1.Current
Dim s As String = dr.Item("ColumnsName").ToString

Using this you dont need any label on the form





Re: Visual Basic Express Edition How to create a string from a field of the selected row

Potato K

That's exactly what I want to do... here is my code now

------

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

On Error GoTo Err_radiantcase_Click

Dim dr As DataRow = Me.LinksBindingSource.Current

Dim s As String = dr.Item("linkurl").ToString

Call Shell("C:\Program Files\Internet Explorer\iexplore.exe " & s, 1)

Exit_radiantcase_Click:

Exit Sub

Err_radiantcase_Click:

MsgBox(Err.Description)

Resume Exit_radiantcase_Click

End Sub

----

However, I get an error of 'Unable to cast object of type 'System.data.datarowview' to type 'system.data.datarow'.... the IDE doesn't give me an error, and it builds fine, but when I click on button1 I get that error in the MsgBox.






Re: Visual Basic Express Edition How to create a string from a field of the selected row

spotty

Change the type to datarowview

Dim dr As DataRowView = Me.LinksBindingSource.Current

 Also use Process.start instead of shell.

 and why dont you try using exception handling ( try catch construct)





Re: Visual Basic Express Edition How to create a string from a field of the selected row

Potato K

Thank you!

process start is very nice, I use firefox (hopfully that's ok to say around here) and it opens my links in a new tab even, that's hawt!

I'll look into exception handling... I'm still really new to this, I actually got my 'error handling' from previous Access projects...

Thanks again for helping me.

-
Edit: I wanted to include what my entire code looks like now just for referance....

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Try

            Dim dr As DataRowView = Me.LinksBindingSource.Current

            Dim s As String = dr.Item("linkurl").ToString

            System.Diagnostics.Process.Start(s, 1)

        Catch ex As System.Exception
            MessageBox.Show("Error: " + ex.Message)
        End Try

    End Sub





Re: Visual Basic Express Edition How to create a string from a field of the selected row

spotty

Glad that worked....

Exception handling will definately simplify your errorhandling code. Its not at all difficult.

Process.STart is really much more flexible than shell as you can simply do something like process.start("abc.txt") and it will load the default application for that file type. Which in this case is notepad with the file loaded. Works for URL's and will load the page in the default browser - so Process.start("www.microsoft.com") would load up in the default web browser, whether than be IE or firefox doesnt matter. THis way you dont need to know or code up the specific application for files. Its really flexible.