How do I create linklabels in a timer controlled datagrid

4 views
Skip to first unread message

don omar

unread,
May 13, 2008, 7:54:11 AM5/13/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi I'm a newbie to vb.net and currently working on a project and have
developed a timer controlled datagrid that reads data from a mysql
db...I wanted to change one of the columns to linklabels instead of
normal text.

I've been reading articles on d net
http://www.codeproject.com/KB/cpp/Datagrid_ColumnStyles.aspx?msg=2549988#xx2549988xx

but have no idea how to
1 subclass the abstract DataGridColumnStyle class.
2 to implement the list of the methods

PLEEEASE ASSIST

Andrew Badera

unread,
May 13, 2008, 2:13:25 PM5/13/08
to DotNetDe...@googlegroups.com
whaaaaaaaaat?

dude, "TemplateColumn"

also, are you sure you mean "DataGrid" and not "GridView" ?
--
--
--Andy Badera
http://higherefficiency.net
http://flipbitsnotburgers.blogspot.com/
http://andrew.badera.us/
http://changeroundup.com/
and...@badera.us
(518) 641-1280
Google me: http://www.google.com/search?q=andrew+badera

omar yusuf

unread,
May 14, 2008, 12:39:03 AM5/14/08
to DotNetDe...@googlegroups.com
Thanks Andrew for d reply...Well I think its datagrid am not sure bout it any more since you brought up dataview.
Do you have any ideas of how to solve this thing?

Cerebrus

unread,
May 14, 2008, 1:20:22 PM5/14/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
You are not sure about what control you are using ? I know it's very
hard work, but could you please take the effort to check and *then*
get back to us ?

omar yusuf

unread,
May 15, 2008, 1:12:11 AM5/15/08
to DotNetDe...@googlegroups.com
Basically I don't mind any control to use as long as my objective is reached. But I'd prefer the datagrid control because I have to dynamically code it so that it looks more better that it currently is

Andrew Badera

unread,
May 15, 2008, 12:32:55 PM5/15/08
to DotNetDe...@googlegroups.com
I already said "TemplateColumn"

GIYF

omar yusuf

unread,
May 16, 2008, 1:59:11 AM5/16/08
to DotNetDe...@googlegroups.com
Hey Andrew thanks. so how do I implement the "TemplateColumn" to my project?

Cerebrus

unread,
May 16, 2008, 12:51:20 PM5/16/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
He also said "GIYF".

http://www.acronymfinder.com/acronym.aspx?rec={B0C6B156-BE26-4F17-B2C6-FB13D93CC530}

In other words, what you're supposed to do is go to the site mentioned
in the link above and type in the first word that Andrew suggested to
you.


On May 16, 10:59 am, "omar yusuf" <yaro...@gmail.com> wrote:
> Hey Andrew thanks. so how do I implement the "TemplateColumn" to my project?
>
>
>
> On Thu, May 15, 2008 at 7:32 PM, Andrew Badera <and...@badera.us> wrote:
> > I already said "TemplateColumn"
>
> > GIYF
>
> > On Thu, May 15, 2008 at 1:12 AM, omar yusuf <yaro...@gmail.com> wrote:
>
> >> Basically I don't mind any control to use as long as my objective is
> >> reached. But I'd prefer the datagrid control because I have to dynamically
> >> code it so that it looks more better that it currently is
>
> >> On Wed, May 14, 2008 at 8:20 PM, Cerebrus <zorg...@sify.com> wrote:
>
> >>> You are not sure about what control you are using ? I know it's very
> >>> hard work, but could you please take the effort to check and *then*
> >>> get back to us ?
>
> >>> On May 14, 9:39 am, "omar yusuf" <yaro...@gmail.com> wrote:
> >>> > Thanks Andrew for d reply...Well I think its datagrid am not sure bout
> >>> it
> >>> > any more since you brought up dataview.
> >>> > Do you have any ideas of how to solve this thing?
>
> > --
> > --
> > --Andy Badera
> >http://higherefficiency.net
> >http://flipbitsnotburgers.blogspot.com/
> >http://andrew.badera.us/
> >http://changeroundup.com/
> > and...@badera.us
> > (518) 641-1280
> > Google me:http://www.google.com/search?q=andrew+badera- Hide quoted text -
>
> - Show quoted text -

Andrew Badera

unread,
May 16, 2008, 12:52:14 PM5/16/08
to DotNetDe...@googlegroups.com
By not being lazy.

omar yusuf

unread,
May 17, 2008, 3:34:42 AM5/17/08
to DotNetDe...@googlegroups.com
Hahahahahaha.....believe me, I agree that GIMF

I found out bout
http://www.codeproject.com/KB/cpp/Datagrid_ColumnStyles.aspx

http://rustemsoft.com/datagridview_columns1.htm#5
http://www.themssforum.com/forum/Winforms/Winforms-9.html
http://www.top-shareware.net/datagrid_columns_net_assembly.html
http://odetocode.com/Blogs/search/SearchResults.aspx?q=dynamically%20coding%20datagrid&f=&u=
http://www.dotnetonweb.com/2518_Tutorial_LinkLabel_DataGrid_Column.html
http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic10033.aspx
http://www.c-sharpcorner.com/UploadFile/sudhakarjalli/ComboBoxInDataGridSKJ11182005002740AM/ComboBoxInDataGridSKJ.aspx
http://www.dreamincode.net/forums/showtopic51798.htm
http://forums.devshed.com/net-development-87/column-styles-in-a-datagrid-vb-net-386726.html
http://forums.devarticles.com/asp-development-3/datagrid-dynamic-update-4968.html
http://www.gridviewguy.com/Articles/29_Creating_Datagrid_columns_programmatically.aspx#
http://j1hammer.blogspot.com/2005/10/how-to-use-datagridcolumnstyles.html
http://www.java2s.com/Code/VB/GUI/UsingLinkLabelstocreatehyperlinksOpenNotepad.htm
http://www.java2s.com/Code/VB/Class/DefineAbstractClassandReferenceClassbyit.htm
http://www.xmlfox.com/datagrid_datagridview.htm

I'm trying to teach myself to code in VB.NET, 2 be honest I've no idea on what I'm doing... When andrew mentioned TemplateColumn I've become more confused
I've researched on DataGridViewColumnStyles & TemplateColumn. I'm confused, people

Cerebrus

unread,
May 18, 2008, 2:49:36 AM5/18/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I think the source of your confusion (and ours, by transference) is
the fact that you have neglected to tell us if you are working on the
Windows forms DataGrid or the Web forms Datagrid. The former does not
have TemplateColumns and you will indeed have to subclass your
DataGridColumn to the type of column you want to render. The latter
can be customized easily using TemplateColumns.

The glaring limitations of the .NET 1.x Datagrid(Windows) were the
reason why third party grid components sold so well. With the advent
of the .NET 2.0 DataGridView (which was built from scratch, rather
than building upon the existing Datagrid control), all those problems
are history.

On May 17, 12:34 pm, "omar yusuf" <yaro...@gmail.com> wrote:
> Hahahahahaha.....believe me, I agree that GIMF
>
> I found out bouthttp://www.codeproject.com/KB/cpp/Datagrid_ColumnStyles.aspx
>
> http://rustemsoft.com/datagridview_columns1.htm#5http://www.themssforum.com/forum/Winforms/Winforms-9.htmlhttp://www.top-shareware.net/datagrid_columns_net_assembly.htmlhttp://odetocode.com/Blogs/search/SearchResults.aspx?q=dynamically%20...http://www.dotnetonweb.com/2518_Tutorial_LinkLabel_DataGrid_Column.htmlhttp://www.devnewsgroups.net/group/microsoft.public.dotnet.framework....http://www.c-sharpcorner.com/UploadFile/sudhakarjalli/ComboBoxInDataG...http://www.dreamincode.net/forums/showtopic51798.htmhttp://forums.devshed.com/net-development-87/column-styles-in-a-datag...http://forums.devarticles.com/asp-development-3/datagrid-dynamic-upda...http://www.gridviewguy.com/Articles/29_Creating_Datagrid_columns_prog...http://j1hammer.blogspot.com/2005/10/how-to-use-datagridcolumnstyles....http://www.java2s.com/Code/VB/GUI/UsingLinkLabelstocreatehyperlinksOp...http://www.java2s.com/Code/VB/Class/DefineAbstractClassandReferenceCl...http://www.xmlfox.com/datagrid_datagridview.htm

omar yusuf

unread,
May 19, 2008, 12:43:47 AM5/19/08
to DotNetDe...@googlegroups.com
Oh I'm sorry Cerebrus that I didn't mention to you that I'm working on a Windows form datagrid.

Cerebrus

unread,
May 19, 2008, 3:18:09 AM5/19/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Then you have your answer.

omar yusuf

unread,
May 19, 2008, 3:34:23 AM5/19/08
to DotNetDe...@googlegroups.com
Atleast dat cleared up my doubts on d TemplateColumn issue...I've doin some coding using datagridviewColumn...its kiilin mi..i need sm help

omar yusuf

unread,
May 19, 2008, 4:27:07 AM5/19/08
to DotNetDe...@googlegroups.com
Can anyone show me how to solve this problem. I want to select the data from a mysql database and assign each row to a set value
 these values are set to the required rows
I'm getting this errror
Property access must assign to the property or use its value.


    Public Sub MySqlReadData(ByVal MyADOConnection As MySqlConnection)

        Dim MySqlDataAdapter As New MySqlDataAdapter("SELECT * FROM message", MyADOConnection)
        Dim MySqlDataSet As New DataSet()

        MySqlCommand.CommandText("INSERT (id, User, Amount, Amount_Currency, Task, Rate, Rate_Currency)" _
        & "VALUES(?id, ?User, ?Amount, ?Amount_Currency, ?Task, ?Rate, ?Rate_Currency)")

        Dim dmTable As New DataTable("Forex Trader")
        dmTable.Columns.Add(New DataColumn("id", GetType(Integer)))
        dmTable.Columns.Add(New DataColumn("User", GetType(String)))
        dmTable.Columns.Add(New DataColumn("Amount", GetType(Integer)))
        dmTable.Columns.Add(New DataColumn("Amount_Currency", GetType(String)))
        dmTable.Columns.Add(New DataColumn("Task", GetType(String)))
        dmTable.Columns.Add(New DataColumn("Rate", GetType(Integer)))
        dmTable.Columns.Add(New DataColumn("Rate_Currency", GetType(String)))

        Dim dr As DataRow = dmTable.NewRow()
        dr("id") = "?id"
        dr("User") = "?User"
        dr("Amount") = "?Amount"
        dr("Amount_Currency") = "?Amount_Currency"
        dr("Task") = "?Task"
        dr("Rate") = "?Rate"
        dr("Rate_Currency") = "?Rate_Currency"
        dmTable.Rows.Add(dr)

        Try
            If (MySqlDataAdapter.Fill(MySqlDataSet) > 0) Then
                MySqlDataGrid.DataSource = MySqlDataSet.Tables(0)

            End If
        Catch MyError As MySqlException
            MessageBox.Show("Error Connecting To Database")
        End Try

    End Sub

don omar

unread,
May 19, 2008, 9:56:09 AM5/19/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I'm using this website as reference
http://www.codeproject.com/KB/cpp/Datagrid_ColumnStyles.aspx

what I had to change is the data row where I have to call data from a
database and insert it into the datagrid

I've created the data table, columns and a datarow.
I'm not sure how to insert the correct data into their respective
columns
finally I'm getting an error of 'TableStyles' is not a member of
'System.Windows.Forms.DataGridView'.


Public Sub MySqlReadData(ByVal MyADOConnection As MySqlConnection)

MySqlDataGrid = New System.Windows.Forms.DataGridView()
Dim MySqlDataAdapter As New MySqlDataAdapter("SELECT * FROM
message", MyADOConnection)
Dim MySqlDataSet As New DataSet()

Dim dmTable As New DataTable("Forex Trader")
dmTable.Columns.Add(New DataColumn("id", GetType(Integer)))
dmTable.Columns.Add(New DataColumn("User", GetType(String)))
dmTable.Columns.Add(New DataColumn("Amount",
GetType(Integer)))
dmTable.Columns.Add(New DataColumn("Amount_Currency",
GetType(String)))
dmTable.Columns.Add(New DataColumn("Task", GetType(String)))
dmTable.Columns.Add(New DataColumn("Rate", GetType(Integer)))
dmTable.Columns.Add(New DataColumn("Rate_Currency",
GetType(String)))



Dim dr As DataRow = dmTable.NewRow()
dr("id") = "id"
dr("User") = "User"
dr("Amount") = "Amount"
dr("Amount_Currency") = "Amount_Currency"
dr("Task") = "Task"
dr("Rate") = "Rate"
dr("Rate_Currency") = "Rate_Currency"
dmTable.Rows.Add(dr)

<b>MySqlDataGrid.TableStyles</b>.Add(CreateTableStyle())
MySqlDataGrid.DataSource = dmTable

Try
If (MySqlDataAdapter.Fill(MySqlDataSet) > 0) Then
MySqlDataGrid.DataSource = MySqlDataSet.Tables(0)

End If
Catch MyError As MySqlException
MessageBox.Show("Error Connecting To Database")
End Try

End Sub


Andrew Badera

unread,
May 19, 2008, 12:43:48 PM5/19/08
to DotNetDe...@googlegroups.com
1. In general, check out Grid View Guy: http://gridviewguy.com/
2. More specifically, are these:


User, Amount, Amount_Currency, Task, Rate, Rate_Currency)" _
        & "VALUES(?id, ?User, ?Amount, ?Amount_Currency, ?Task, ?Rate, ?Rate_Currency


all public properties of your class? If so, make sure they all have get accessors. However, if they're backed by a private field, use the private field instead.

--Andy Badera

Cerebrus

unread,
May 19, 2008, 12:48:05 PM5/19/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Okay, now we seem to be getting somewhere.

When you tell us about compile time errors, always make sure to
indicate the line that is showing the error. It's very difficult to
identify the errant line like this.

On May 19, 1:27 pm, "omar yusuf" <yaro...@gmail.com> wrote:
> Can anyone show me how to solve this problem. I want to select the data from
> a mysql database and assign each row to a set value
>  these values are set to the required rows
> I'm getting this errror
> *Property access must assign to the property or use its value.*
>
>     Public Sub MySqlReadData(ByVal MyADOConnection As MySqlConnection)
>
>         Dim MySqlDataAdapter As New MySqlDataAdapter("SELECT * FROM
> message", MyADOConnection)
>         Dim MySqlDataSet As New DataSet()
>
>         *MySqlCommand.CommandText("INSERT (id, User, Amount,
> Amount_Currency, Task, Rate, Rate_Currency)" _
>         & "VALUES(?id, ?User, ?Amount, ?Amount_Currency, ?Task, ?Rate,
> ?Rate_Currency)")
> *
> > On Mon, May 19, 2008 at 10:18 AM, Cerebrus <zorg...@sify.com> wrote:
>
> >> Then you have your answer.
>
> >> On May 19, 9:43 am, "omar yusuf" <yaro...@gmail.com> wrote:
> >> > Oh I'm sorry Cerebrus that I didn't mention to you that I'm working on a
> >> > Windows form datagrid.- Hide quoted text -

omar yusuf

unread,
May 20, 2008, 4:45:37 AM5/20/08
to DotNetDe...@googlegroups.com
I already have a working datagrid, is it possible to add an extra sublclass to change the column to linklabels?

omar yusuf

unread,
May 20, 2008, 4:49:04 AM5/20/08
to DotNetDe...@googlegroups.com
Oh sorry

Error is 'TableStyles' is not a member of 'System.Windows.Forms.DataGridView'.



    Public Sub MySqlReadData(ByVal MyADOConnection As MySqlConnection)

        MySqlDataGrid = New System.Windows.Forms.DataGridView()

        Dim MySqlDataAdapter As New MySqlDataAdapter("SELECT * FROM message", MyADOConnection)
        Dim MySqlDataSet As New DataSet()

        Dim dmTable As New DataTable("Forex Trader")
        dmTable.Columns.Add(New DataColumn("id", GetType(Integer)))
        dmTable.Columns.Add(New DataColumn("User", GetType(String)))
        dmTable.Columns.Add(New DataColumn("Amount", GetType(Integer)))
        dmTable.Columns.Add(New DataColumn("Amount_Currency", GetType(String)))
        dmTable.Columns.Add(New DataColumn("Task", GetType(String)))
        dmTable.Columns.Add(New DataColumn("Rate", GetType(Integer)))
        dmTable.Columns.Add(New DataColumn("Rate_Currency", GetType(String)))



        Dim dr As DataRow = dmTable.NewRow()
        dr("id") = "id"
        dr("User") = "User"
        dr("Amount") = "Amount"
        dr("Amount_Currency") = "Amount_Currency"
        dr("Task") = "Task"
        dr("Rate") = "Rate"
        dr("Rate_Currency") = "Rate_Currency"
        dmTable.Rows.Add(dr)

        MySqlDataGrid.TableStyles.Add(CreateTableStyle())
        MySqlDataGrid.DataSource = dmTable


        Try
            If (MySqlDataAdapter.Fill(MySqlDataSet) > 0) Then
                MySqlDataGrid.DataSource = MySqlDataSet.Tables(0)

            End If
        Catch MyError As MySqlException
            MessageBox.Show("Error Connecting To Database")
        End Try

    End Sub

Cerebrus

unread,
May 21, 2008, 1:23:30 AM5/21/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Do my eyes deceive me or did you still neglect to indicate the line
with the error ?
>         *MySqlDataGrid.TableStyles.Add(CreateTableStyle())*
>         MySqlDataGrid.DataSource = dmTable
>
>         Try
>             If (MySqlDataAdapter.Fill(MySqlDataSet) > 0) Then
>                 MySqlDataGrid.DataSource = MySqlDataSet.Tables(0)
>
>             End If
>         Catch MyError As MySqlException
>             MessageBox.Show("Error Connecting To Database")
>         End Try
>
>     End Sub
>
>
>
> On Tue, May 20, 2008 at 11:45 AM, omar yusuf <yaro...@gmail.com> wrote:
> > I already have a working datagrid, is it possible to add an extra sublclass
> > to change the column to linklabels?
>
> >> > - Show quoted text -- Hide quoted text -

omar yusuf

unread,
May 21, 2008, 1:30:40 AM5/21/08
to DotNetDe...@googlegroups.com

> <b>ERROR OCCURS HERE =>>MySqlDataGrid.TableStyles.Add(CreateTableStyle())</b>
>

MySqlDataGrid.DataSource = dmTable
>
> Try
> If (MySqlDataAdapter.Fill(MySqlDataSet) > 0) Then
> MySqlDataGrid.DataSource = MySqlDataSet.Tables(0)
>
> End If
> Catch MyError As MySqlException
> MessageBox.Show("Error Connecting To Database")
> End Try
>
> End Sub

omar yusuf

unread,
May 29, 2008, 2:04:07 AM5/29/08
to DotNetDe...@googlegroups.com
Hi there guys
Below is the code for the working datagrid
Below is the code for calling the rows of data into the datagrid



    Public Sub MySqlReadData(ByVal MyADOConnection As MySqlConnection)

        Dim MySqlDataAdapter As New MySqlDataAdapter("SELECT * FROM message ORDER BY id DESC", MyADOConnection)

        Dim MySqlDataSet As New DataSet()

        Try

            If (MySqlDataAdapter.Fill(MySqlDataSet) > 0) Then
                MySqlDataGrid.DataSource = MySqlDataSet.Tables(0)

            End If
        Catch MyError As MySqlException
            MessageBox.Show("Error Connecting To Database")
        End Try

    End Sub

I created another sub class for dynamically programmed datagrid.
   
Private Function CreateTableStyle()

        Dim TblStyle As New DataGridTableStyle()
        TblStyle.MappingName = "Forex Trader"

        Dim cbid As New ColumnStyles.DataGridLinkLabelColumn
        AddHandler cbid.LinkClicked, AddressOf cbid_LinkClicked
        cbid.MappingName = "id"
        cbid.HeaderText = "Transaction No."
        cbid.Width = 40

        Dim cbuser As New DataGridTextBoxColumn
        cbuser.MappingName = "User"
        cbuser.HeaderText = "User"
        cbuser.Width = 40

        Dim cbamount As New DataGridTextBoxColumn
        cbamount.MappingName = "Amount"
        cbamount.HeaderText = "Amount"
        cbamount.Width = 40

        Dim cbamountcurrency As New DataGridTextBoxColumn
        cbamountcurrency.MappingName = "Amount_Currency"
        cbamountcurrency.HeaderText = "Amount Currency"
        cbamountcurrency.Width = 40

        Dim cbtask As New DataGridTextBoxColumn
        cbtask.MappingName = "Task"
        cbtask.HeaderText = "Task"
        cbtask.Width = 40

        Dim cbrate As New DataGridTextBoxColumn
        cbrate.MappingName = "Rate"
        cbrate.HeaderText = "Rate"
        cbrate.Width = 40

        Dim cbratecurrency As New DataGridTextBoxColumn
        cbratecurrency.MappingName = "Rate_Currency"
        cbratecurrency.HeaderText = "Rate Currency"
        cbratecurrency.Width = 40

        TblStyle.GridColumnStyles.Add(cbid)
        TblStyle.GridColumnStyles.Add(cbamount)
        TblStyle.GridColumnStyles.Add(cbamountcurrency)
        TblStyle.GridColumnStyles.Add(cbtask)
        TblStyle.GridColumnStyles.Add(cbrate)
        TblStyle.GridColumnStyles.Add(cbratecurrency)

        MySqlDataGrid.TableStyles.Add(TblStyle)

        Return TblStyle

    End Function

What am I missing?
Reply all
Reply to author
Forward
0 new messages