I believe you will need to create a Protected Function for this purpose and in the column where you place the dropdownlist you will need to specify that function to be called when the index changes. The reason for this is that the objects inside the datagrid are created at runtime and therefore are not attached to any one function.
how to convert an existing data in database to a string, in DataGrid
" i need something similar to : lstV.SubItems.Add(dt.Rows(i)("MTimeIN").ToString) which is used in list view" i need it in dataGrid
I hope I'm understanding the question correctly...
You want to replace the functionality of adding items to a ListView to an equivilent of adding items to a DataGrid, correct?
A DataGrid doesn't maintain collections of objects like a list view does. It's bound to datasources that maintain those collections. So, create a DataTable object with a DataColumn, add your items to that table and bind the DataGrid to that DataTable.
I know that in Java that "This." is required for accessing objects local to a form, etc. I also know that in VB.NET you CAN use "Me." for a similar purpose. I have never used it personally in my own code other than for Windows forms like "Me.Close()" but I have seen other people use it quite a bit and I noticed that in 1.1 the generated code always used "Me.". Is that just a programming style or is there more to it than that?
It's just a programming style. The compiler assumes Me. unless otherwise specified. Some people overuse it to death, putting Me. in front of everything, making the code painfully to read, even more so in the C# world with this.. It just makes your code easier to read in certain situations by taking away some abiguity, like in Property methods:
Public Class SomeClass
Private x As Integer
Public Property X() As Integer
Set(ByVal value As Integer)
Me.x = value
I've just seen C# code with this. on every single line where it's legal to put it. I can only sit back and watch as those four keys scrumble to bits of plastic as this is typed about 2,000 times per class file!
If your control is not redrawing after an Invalidate, you're got a serious design problem. Invalidate will send the WM_PAINT message to your control (window message pump actually) which will call your controls Paint handler. If your not getting that message or your code is doing something it shouldn't be, to prevent it from painting!, in the Paint handler, then you've got to examine how you've written your painting code.
I am planning to create an enum at runtime and set it as a property of a class.
Public Property Type As (New Created Enum)
For creating an enum at runtime I have used the following code
Public Function CreateEnum() As [Enum]
Dim domain As AppDomain
domain = Threading.Thread.GetDomain
Dim name As New System.Reflection.AssemblyName
name.Name = "EnumCounters"
Dim asmBuilder As System.Reflection.emit.AssemblyBuilder
asmBuilder = domain.DefineDynamicAssembly(name, Reflection.Emit.AssemblyBuilderAccess.Run)
Dim modBuilder As ModuleBuilder
modBuilder = asmBuilder.DefineDynamicModule("EnumModule")
Dim enumBuilder As EnumBuilder
enumBuilder = modBuilder.DefineEnum("EnumCounters", TypeAttributes.Public, GetType(Integer))
'----- HERE IS WHERE I ADD THE ITEMS
For i As Integer = 0 To DiagManager.Counters.Count - 1
enumBuilder.DefineLiteral(CType(DiagManager.Counters(i), Counter).Caption, i)
Dim enumType As Type = enumBuilder.CreateType
Dim enumObj As [Enum] = System.Activator.CreateInstance(enumType)
Then, I set my property's value as the returned value of the function.
For full code please see (http://emreyazici.com/CodeFormatter.htm -- site does not have banners or advertisement. I only wrote the code)
Normally it would work. But when I assign the 'selectedobject' property of 'property grid' to the created instance of class, it does only display the FIRST item of enum in the property grid
I think the problem is that your property returns a general object. Take this code for example. You'll see that the property works fine when I specifically declare it as my enumerator. However, things don't work as well if I make a simple change of declaring the property as an object. I'm not sure how to accomplish what you want but I do know this is why your having a problem.
'Requires a propertygrid
Public Class Form1
Dim test As New TestEnum
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
PropertyGrid1.SelectedObject = test
Public Class TestEnum
Dim _TestMyEnum As MyEnum
'This works just fine because we have declared the property as MyEnum
Public Property TestMyEnum() As MyEnum
Set(ByVal value As MyEnum)
_TestMyEnum = value
'This returns the exact same enumerator but has been declared as a general object
'The same problem occurs here as you are seeing in your code
Public Property TestMyEnumObject() As Object
Set(ByVal value As Object)
_TestMyEnum = value
Public Enum MyEnum