10 Replies - 686 Views - Last Post: 09 April 2013 - 09:42 AM Rate Topic: -----

#1 pooya1072  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 10-August 12

question about add a property under columns() property in Datagridview

Posted 09 April 2013 - 07:47 AM

hi
yesterday i asked a question related by creating new class and inheritance.
some friends answer . but in an exercise i have a problem. in Datagridview there is a property named Columns . it can used in 3 way .
1-without parameter
2-with index
3-with column name

i want to add a new propery named Equation under columns(index) . so after that i must could do this...
for example i want in column by index=1 do this :
Datagridview1.columns(1).Equation=""


what is the steps of this?

Is This A Good Question/Topic? 0
  • +

Replies To: question about add a property under columns() property in Datagridview

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,155
  • Joined: 12-June 08

Re: question about add a property under columns() property in Datagridview

Posted 09 April 2013 - 08:13 AM

The index is created by the order you added the columns... that or the index in the dataset you would have added as a datasource.

Additionally - you would add columns by using the column's "add" method.
                    Dim foo As New DataGridView
                    foo.Columns.Add(....)

Was This Post Helpful? 0
  • +
  • -

#3 Graywalker  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 22-February 13

Re: question about add a property under columns() property in Datagridview

Posted 09 April 2013 - 08:27 AM

It seems what you are wanting to do is impossible and not sure what the purpose would be...

Found This link that might help more.

What is the purpose of the .Equation? Like, "add an equation to every row under column 1" or what??
Was This Post Helpful? 0
  • +
  • -

#4 pooya1072  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 10-August 12

Re: question about add a property under columns() property in Datagridview

Posted 09 April 2013 - 08:28 AM

mybe i said bad ... i want to add a property named Equation as string and i want access it like this :
Datagridview1.columns(1).Equation=""

Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,155
  • Joined: 12-June 08

Re: question about add a property under columns() property in Datagridview

Posted 09 April 2013 - 08:31 AM

Then you need to make/extend the column object to be a custom object that also includes that property. You'll need to make a new class for it.
Was This Post Helpful? 0
  • +
  • -

#6 pooya1072  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 10-August 12

Re: question about add a property under columns() property in Datagridview

Posted 09 April 2013 - 08:44 AM

View PostGraywalker, on 09 April 2013 - 08:27 AM, said:

It seems what you are wanting to do is impossible and not sure what the purpose would be...

Found This link that might help more.

What is the purpose of the .Equation? Like, "add an equation to every row under column 1" or what??

now i wonder ... see this :
Public Class MyDatagridview
   inherits Datagridview
   public Sub Test()
      MsgBox "test"
   End Sub
   Public Property P1() as integer
End Class


now i Rebuild the project and add MyDatagridview to my project . now i can access Test() method or P1 property . so you mean there is no way to add a property named X as i access it after columns(1).
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,155
  • Joined: 12-June 08

Re: question about add a property under columns() property in Datagridview

Posted 09 April 2013 - 08:45 AM

I am pretty certain I said you need to make a custom DataGridViewColumn... not the grid.
Was This Post Helpful? 0
  • +
  • -

#8 pooya1072  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 10-August 12

Re: question about add a property under columns() property in Datagridview

Posted 09 April 2013 - 08:51 AM

View Postmodi123_1, on 09 April 2013 - 08:31 AM, said:

Then you need to make/extend the column object to be a custom object that also includes that property. You'll need to make a new class for it.

you are right
please show me how with a simple example .
i am working on it for 1 week but cant solve it .
Was This Post Helpful? 0
  • +
  • -

#9 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,155
  • Joined: 12-June 08

Re: question about add a property under columns() property in Datagridview

Posted 09 April 2013 - 08:53 AM

You just showed how you can extend a new datagridview.. same principle.
Was This Post Helpful? 0
  • +
  • -

#10 pooya1072  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 10-August 12

Re: question about add a property under columns() property in Datagridview

Posted 09 April 2013 - 09:24 AM

View Postmodi123_1, on 09 April 2013 - 08:53 AM, said:

You just showed how you can extend a new datagridview.. same principle.

ok... i tried it:
Public Class MyDatagridviewColumn
    Inherits DatagridviewColumn
    Public Sub Test()
        MsgBox("test")
    End Sub
    Public Property P1() As Integer
End Class

then :
Public Class MyDatagridview
    Inherits DataGridView
    Dim c As DataGridViewColumn
    Public Property Columns() As MyDatagridviewColumn
End Class


but there is a property named Columns and i must overload or shodow this property . but i just want to add test() to it .
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,155
  • Joined: 12-June 08

Re: question about add a property under columns() property in Datagridview

Posted 09 April 2013 - 09:42 AM

What exactly do you think you are doing there? You just need to create a custom column and you add it to the grid normally. No need for a custom grid.. no need for a free floating column object in the custom grid.. just extend a DGV column, and add it normal to any ol' grid. You should also go back and reread about object inheritance and how that works.

Public Class MyColumn
    Inherits DataGridViewTextBoxColumn


    Public Function Foo()
        Return "foo123"
    End Function
End Class


'-- in my main
        Dim bar As New DataGridView
 
        bar.Columns.Add(New MyColumn)
        Console.WriteLine(CType(bar.Columns(0), MyColumn).Foo)





Stop thrashing around and think about it.
1. I need a custom column
2. If I make my custom column inherit from an existing column data type I can (more than likely) use it in the grid's 'column collection'... since, with inheritence, the custom grid "is a" varient of the existing column type.
3. If I want the collection to know I am using my custom column I need to make sure to cast it to the right type when trying to access my methods inside the custom column.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1