|
the control name is generated in a string variable.
I just want to get this control , and after I just want to use the enabled property ( so doesn't matter what kind of control is because all have the enabled property ).
But I don't know how to get this control by the name as a string.
|
|
|
|
|
By control name do you mean the member name like MyForm.SomeControl or the Name-property of the control MyForm.SomeControl.Name ?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I mean I have a variable with the control's name for example
cname="MyTextBox1"
|
|
|
|
|
Suggested solution: A custom base class for your forms:
Imports System.Reflection
Imports System.Windows.Forms
Public Class MyBaseForm
Inherits Form
Public Function IsControlEnabled(controlMemberName As String) As Boolean
Dim control As Object = Me.GetType().GetProperty(controlMemberName, BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public).GetValue(Me, Nothing)
Return CBool(GetType(Control).GetProperty("Enabled").GetValue(control, Nothing))
End Function
End Class
In case you already have a custom base class for your forms you can just copy that method in there.
In the previously posted code you have to change accordingly from Form to MyBaseForm:
Dim form As MyBaseForm = DirectCast(Activator.CreateInstance(formType), MyBaseForm)
And then you can simply call form.IsControlEnabled("MyControlName") to get the value of the Enabled-property of the control with the specified member-name.
edit: Don't know why I didn't think of that in the first place - it would make sense to implement it as an extension method for the Form-class instead.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
modified 5-Jun-15 3:36am.
|
|
|
|
|
I am asking this question since this is the first time that I have been asked to work on a vb.net 2010 desktop application.
I have been asked to accomplish the following tasks:
- Add a dropdown list box to ask the user what vendor they want to work with. There will be a default vendor always selected.
- Add a dropdown list box to ask the user what access 2013 database file they would like to work with. A default Access 2013 name will be in the dropdown list box.
Thus can you tell me how to accomplish this goal and/or point me to urls (links) that will tell me how to complete the complete these requests?
|
|
|
|
|
This is such a wide open, basic question that it cannot be answered in a forum post. So...
Create a winforms applciation.
add 2 listboxes to the main form
create a collection of vendors and database locations in code behind
set the collections to the datasource of the list boxes
deal with the selected item and or save event
close the form.
I suggest you look for some very basic tutorials on vb development or buy a book and work through the examples.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello !
I have a vb.net program with sql server 2008r2 database
I'm using Entity Framework 6.
On each database's table there's a column "ToDelete" that may have the value true or false.
What is the shortest way to " Delete all records from all tables that have the ToDelete=True"
Thank you !
|
|
|
|
|
A statement like the following will yield the appropriate DELETE statements:
SELECT 'DELETE FROM ['
+ A.[name] + '].['
+ B.[name] + '] WHERE ['
+ C.[name] + ']=1'
FROM [sys].[schemas] A
INNER JOIN [sys].[objects] B
ON A.[schema_id]=B.[schema_id]
INNER JOIN [sys].[columns] C
ON B.[object_id]=C.[object_id]
INNER JOIN [sys].[types] D
ON C.[system_type_id]=D.[system_type_id]
WHERE B.[schema_id]!=4
AND C.[name]='ToDelete'
AND D.[name]='boolean'
In a procedure, you could use a cursor to iterate the results and use an EXECUTE statement on each.
Or in code, you could pass each to an ExecuteNonQuery call.
|
|
|
|
|
Hah that picks up views as well
You have that in your model database don't you! I've seen some weird utilities and that one is right up there.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Ok, that's a small whoops, but easily remedied. No, I don't use that, I just whipped it up in response to the question.
|
|
|
|
|
Sorry friend but I'm using Entity framework. I mean shortest way using entity framework.
|
|
|
|
|
Use the right tool for the right job.
|
|
|
|
|
you are saying that no way to do this with entity Framework ?
|
|
|
|
|
No. In fact I don't know enough about Entity Framework to know what it can and can't do, but I understand that it can execute a procedure.
|
|
|
|
|
Haven't we had this conversation recently!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Something like this should work:
Using transaction As DbContextTransaction = yourContext.Database.BeginTransaction()
Const query As String = "SELECT N'DELETE FROM ' + QUOTENAME(A.[name]) + N'.' + QUOTENAME(B.[name]) + N' WHERE ' + QUOTENAME(C.[name]) + N' = 1' As CommandText FROM sys.schemas As A INNER JOIN sys.objects As B ON B.schema_id = A.schema_id INNER JOIN sys.columns As C ON C.object_id = B.object_id INNER JOIN sys.types As D ON D.system_type_id = C.system_type_id WHERE A.[schema_id] != 4 And B.[type] = 'U' And C.[name] = 'ToDelete' And D.[name] = 'bit';"
Dim commandsToExecute As List(Of String) = context.Database.SqlQuery(Of String)(query).ToList()
For Each command As String In commandsToExecute
yourContext.Database.ExecuteSqlCommand(command)
Next
transaction.Commit()
End Using
Entity Framework : Raw SQL Queries[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
In the link on your post , I red that this can be applied on Entity Framework with Code First.
I'm using Database First ???
|
|
|
|
|
Does your context class inherit from DbContext or ObjectContext ? If it's DbContext , then the code I posted should work.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Public Function isAdministrator(AdminLevelID As Integer) As Boolean
Dim DBComm As DbCommand
Dim strsql As String = ""
strsql = "SELECT IsAdministrator FROM tb_GE_AdminLevel WHERE SysID =" & AdminLevelID
Return (DBComm.ExecuteScalar(strsql))
End Function
Public Function GetAllAdminMenu(ByVal AdminLevelID As Integer, Optional ByVal CustomerID As Integer = 0) As DataTable
Dim dt As New DataTable
Dim dbcommSave As DbCommand
Dim strSql As String = ""
Try
If (isAdministrator(AdminLevelID)) Then
strSql = "SELECT AdminMenuID,AdminMenuName,ParentID,IsNull((Select 1 As Allow from [tb_GE_AdminLevelMenu] Where AdminMenuID = A.AdminMenuID AND SysID = " & AdminLevelID & " ),0) As checked FROM tb_GE_AdminMenu As A ORDER BY SrNo"
Else
strSql = "SELECT AdminMenuID,AdminMenuName,ParentID,IsNull((Select 1 As Allow from [tb_GE_AdminLevelMenu] Where AdminMenuID = A.AdminMenuID AND SysID=1),0) As checked FROM tb_GE_AdminMenu As A ORDER BY SrNo"
End If
''strSql = "SELECT MenuID,MenuName,ParentID FROM tb_GE_Menu ORDER BY SrNo"
dbcommSave = Db.GetSqlStringCommand(strSql)
dt.Load(Db.ExecuteReader(dbcommSave))
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "SQL Exception")
End Try
Return dt
End Function
|
|
|
|
|
You can't solve what? You have not asked a question.
Say what problem you are having, any error messages etc, and what you are trying to do, as we are not telepathic
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Sorry
The "isAdministrator" returned null value!
|
|
|
|
|
|
Solve what? You haven't said what the problem is. We can't read your mind or see your screen so you have to explain it to us.
|
|
|
|
|
Okay, Fine!
I'm sorry!
|
|
|
|