• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

extending an object of a class without making a new class?

I want to extend the functionality of textbox, so that it returns Null if its text is empty instead of an empty string...

however I don't want to create a new extended class, I just want to extend that particular textbox.

Is this possible?
0
majnun
Asked:
majnun
  • 8
  • 5
  • 3
1 Solution
 
b1xml2Commented:
well, just use a property and encapsulate the Text property of the TextBox


private string MyText
{
      get { return box.Text.Trim().Length == 0 ? null : box.Text.Trim(); }
      set { box.Text = value; }
}
0
 
b1xml2Commented:
apologies, thought this was C# initially

Public Property MyText() As String
      Get
            Dim value As String = Nothing
            If box.Text.Trim().Length > 0 Then
                  value = box.Text.Trim()
            End If
            Return value
            
      End Get
      
      Set (ByVal value As String)
            box.Text = value
      End Set

End Property
0
 
majnunAuthor Commented:
I don't want to create a new property, I want to change how the textbox.text property works... also I need to change it during run time, such as while looping through a collection of controls.

Thanks!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
b1xml2Commented:
The only way to do what you want is to use subclass... There's no way out of this. Actually, what is the difficulty in creating a class that inherits from the TextBox and just overriding the Text property of the TextBox. Seems to me to be the best way to go.
0
 
Bob LearnedCommented:
Is this in relation to data-binding to a database?  You want the table field to be Null instead of an empty string, right?

Bob
0
 
majnunAuthor Commented:
TheLearnedOne

You really are learned, that is exactly the reason.

So what do i do?
0
 
Bob LearnedCommented:
How are you accessing the database?  Do you have any code to highlight?

Bob
0
 
majnunAuthor Commented:
My code is dynamically created, spread over a bunch of functions in a class... its really clever but messy to look at if you don't want to pour over hundreds of lines of code...

Essentially:
I am using oledb connection to access database
I am creating adapters for each related table
I create commands using commandText with parameters
I am creating a primary key column for each table that corresponds to an autonumber primary key
I fill a dataset from each of the adapters i have created
I create datarelations between the tables in the dataset
I bind controls to columns of particular tables in the dataset.
I use form's binding context to move through the dataset table

If you really really want to see the code i'll post it, but the above info I'm hoping will suffice.
0
 
Bob LearnedCommented:
Does the DataAdapter have an UpdateCommand?

Bob
0
 
majnunAuthor Commented:
You betcha.
0
 
majnunAuthor Commented:
Update command with parameters (if it matters).
0
 
Bob LearnedCommented:
I am fresh out of ideas.  I can't seem to find any way around this.

Bob
0
 
majnunAuthor Commented:
Yeah, I tried changing the value of the field to dbnull.value during the RowUpdating event of the adapter, but it seems that doesn't work because by the time the adapter is updating the column has a type of string, and I can't change that, and it seems to convert dbnull.value to an empty string anyway.

It just seems odd to me that MS didn't address this directly, since Access is one of their programs and , and people without $ for SQL server use mdb files. Oh well.

So, then I guess I'll just make all the fields allow zero length string, or extend the controls to return null instread of an empty string.

And b1xml2 is correct? You can't modify an instanced object's members during run time?
0
 
majnunAuthor Commented:
I mean add/remove/or modify how their public methods behave.
0
 
Bob LearnedCommented:
That is correct AFAIK, that you can't modify members during run-time.  There might be some "magic" code in CodeDOM, or Reflection, but I don't have any specific knowledge to that effect.

Bob
0
 
majnunAuthor Commented:
Ok, well I'll close out the question and award points b1xml2 since he was the first to answer the question posed.

Bob:
I appreciate your help on the particular matter driving the question, and if you have further insight into that problem please post at:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21388792.html

I accidentally closed that question because I tested it incorrectly and it seemed to work when it really didn't, and if you want points for your answer I can just open another question for you to answer.

Thanks all!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 8
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now