473,770 Members | 5,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Text limit on DataGrid Column

Is there a way to put a limit on the text size of a datagrid column?

Thanks,
Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #1
6 6525
Hi,

Here is a column style that i wrote that allows you set set max
length and character casing. Use it instead of a datagridtextbox column in
your datagrid tablestyle.

Imports System.Drawing

Imports System.Drawing. Drawing2D

Imports System.Windows. Forms

Imports System.Componen tModel

<DataSysDescrip tion("This column style adds Max length and Character Casing
to the datagrid textbox column")> _

Public Class ExtendedTextBox Column

Inherits DataGridTextBox Column

Dim mccText As CharacterCasing = CharacterCasing .Normal

Dim mintMaxLength As Integer = 0

<DataSysDescrip tion("Upper, Lower, or Normal")> _

Public Property TextCharacterCa sing() As CharacterCasing

Get

Return mccText

End Get

Set(ByVal Value As CharacterCasing )

mccText = Value

End Set

End Property

<DataSysDescrip tion("Max Length of Text. Use 0 to retrieve full text")> _

Public Property MaxLength() As Integer

Get

Return mintMaxLength

End Get

Set(ByVal Value As Integer)

mintMaxLength = Value

End Set

End Property

Protected Overloads Overrides Sub Edit(ByVal source As
System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal bounds
As System.Drawing. Rectangle, ByVal [readOnly] As Boolean, ByVal instantText
As String, ByVal cellIsVisible As Boolean)

MyBase.Edit(sou rce, rowNum, bounds, [readOnly], instantText, cellIsVisible)

MyBase.TextBox. CharacterCasing = mccText

If mintMaxLength > 0 Then MyBase.TextBox. MaxLength = mintMaxLength

End Sub

Protected Overrides Function GetColumnValueA tRow(ByVal source As
System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer) As Object

Dim obj As String

Dim strReturn As String

obj = MyBase.GetColum nValueAtRow(sou rce, rowNum).ToStrin g

Select Case mccText

Case CharacterCasing .Lower

strReturn = obj.ToLower

Case CharacterCasing .Upper

strReturn = obj.ToUpper

Case CharacterCasing .Normal

strReturn = obj

End Select

If mintMaxLength > 0 And strReturn.Lengt h > mintMaxLength Then

strReturn = strReturn.Subst ring(0, mintMaxLength)

End If

Return strReturn

End Function

End Class

Ken

------------------------

"Aaron Smith" <th**********@s mithcentral.net > wrote in message
news:8l******** *********@newss vr16.news.prodi gy.com...
Is there a way to put a limit on the text size of a datagrid column?

Thanks,
Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #2
Hi,

Here is a column style that i wrote that allows you set set max
length and character casing. Use it instead of a datagridtextbox column in
your datagrid tablestyle.

Imports System.Drawing

Imports System.Drawing. Drawing2D

Imports System.Windows. Forms

Imports System.Componen tModel

<DataSysDescrip tion("This column style adds Max length and Character Casing
to the datagrid textbox column")> _

Public Class ExtendedTextBox Column

Inherits DataGridTextBox Column

Dim mccText As CharacterCasing = CharacterCasing .Normal

Dim mintMaxLength As Integer = 0

<DataSysDescrip tion("Upper, Lower, or Normal")> _

Public Property TextCharacterCa sing() As CharacterCasing

Get

Return mccText

End Get

Set(ByVal Value As CharacterCasing )

mccText = Value

End Set

End Property

<DataSysDescrip tion("Max Length of Text. Use 0 to retrieve full text")> _

Public Property MaxLength() As Integer

Get

Return mintMaxLength

End Get

Set(ByVal Value As Integer)

mintMaxLength = Value

End Set

End Property

Protected Overloads Overrides Sub Edit(ByVal source As
System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal bounds
As System.Drawing. Rectangle, ByVal [readOnly] As Boolean, ByVal instantText
As String, ByVal cellIsVisible As Boolean)

MyBase.Edit(sou rce, rowNum, bounds, [readOnly], instantText, cellIsVisible)

MyBase.TextBox. CharacterCasing = mccText

If mintMaxLength > 0 Then MyBase.TextBox. MaxLength = mintMaxLength

End Sub

Protected Overrides Function GetColumnValueA tRow(ByVal source As
System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer) As Object

Dim obj As String

Dim strReturn As String

obj = MyBase.GetColum nValueAtRow(sou rce, rowNum).ToStrin g

Select Case mccText

Case CharacterCasing .Lower

strReturn = obj.ToLower

Case CharacterCasing .Upper

strReturn = obj.ToUpper

Case CharacterCasing .Normal

strReturn = obj

End Select

If mintMaxLength > 0 And strReturn.Lengt h > mintMaxLength Then

strReturn = strReturn.Subst ring(0, mintMaxLength)

End If

Return strReturn

End Function

End Class

Ken

------------------------

"Aaron Smith" <th**********@s mithcentral.net > wrote in message
news:8l******** *********@newss vr16.news.prodi gy.com...
Is there a way to put a limit on the text size of a datagrid column?

Thanks,
Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #3
That works perfectly, Ken. Thank you very much.

Ken Tucker [MVP] wrote:
Hi,

Here is a column style that i wrote that allows you set set max
length and character casing. Use it instead of a datagridtextbox column in
your datagrid tablestyle.

Imports System.Drawing

Imports System.Drawing. Drawing2D

Imports System.Windows. Forms

Imports System.Componen tModel

<DataSysDescrip tion("This column style adds Max length and Character Casing
to the datagrid textbox column")> _

Public Class ExtendedTextBox Column

Inherits DataGridTextBox Column

Dim mccText As CharacterCasing = CharacterCasing .Normal

Dim mintMaxLength As Integer = 0

<DataSysDescrip tion("Upper, Lower, or Normal")> _

Public Property TextCharacterCa sing() As CharacterCasing

Get

Return mccText

End Get

Set(ByVal Value As CharacterCasing )

mccText = Value

End Set

End Property

<DataSysDescrip tion("Max Length of Text. Use 0 to retrieve full text")> _

Public Property MaxLength() As Integer

Get

Return mintMaxLength

End Get

Set(ByVal Value As Integer)

mintMaxLength = Value

End Set

End Property

Protected Overloads Overrides Sub Edit(ByVal source As
System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal bounds
As System.Drawing. Rectangle, ByVal [readOnly] As Boolean, ByVal instantText
As String, ByVal cellIsVisible As Boolean)

MyBase.Edit(sou rce, rowNum, bounds, [readOnly], instantText, cellIsVisible)

MyBase.TextBox. CharacterCasing = mccText

If mintMaxLength > 0 Then MyBase.TextBox. MaxLength = mintMaxLength

End Sub

Protected Overrides Function GetColumnValueA tRow(ByVal source As
System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer) As Object

Dim obj As String

Dim strReturn As String

obj = MyBase.GetColum nValueAtRow(sou rce, rowNum).ToStrin g

Select Case mccText

Case CharacterCasing .Lower

strReturn = obj.ToLower

Case CharacterCasing .Upper

strReturn = obj.ToUpper

Case CharacterCasing .Normal

strReturn = obj

End Select

If mintMaxLength > 0 And strReturn.Lengt h > mintMaxLength Then

strReturn = strReturn.Subst ring(0, mintMaxLength)

End If

Return strReturn

End Function

End Class

Ken

------------------------

"Aaron Smith" <th**********@s mithcentral.net > wrote in message
news:8l******** *********@newss vr16.news.prodi gy.com...
Is there a way to put a limit on the text size of a datagrid column?

Thanks,
Aaron

--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #4
That works perfectly, Ken. Thank you very much.

Ken Tucker [MVP] wrote:
Hi,

Here is a column style that i wrote that allows you set set max
length and character casing. Use it instead of a datagridtextbox column in
your datagrid tablestyle.

Imports System.Drawing

Imports System.Drawing. Drawing2D

Imports System.Windows. Forms

Imports System.Componen tModel

<DataSysDescrip tion("This column style adds Max length and Character Casing
to the datagrid textbox column")> _

Public Class ExtendedTextBox Column

Inherits DataGridTextBox Column

Dim mccText As CharacterCasing = CharacterCasing .Normal

Dim mintMaxLength As Integer = 0

<DataSysDescrip tion("Upper, Lower, or Normal")> _

Public Property TextCharacterCa sing() As CharacterCasing

Get

Return mccText

End Get

Set(ByVal Value As CharacterCasing )

mccText = Value

End Set

End Property

<DataSysDescrip tion("Max Length of Text. Use 0 to retrieve full text")> _

Public Property MaxLength() As Integer

Get

Return mintMaxLength

End Get

Set(ByVal Value As Integer)

mintMaxLength = Value

End Set

End Property

Protected Overloads Overrides Sub Edit(ByVal source As
System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal bounds
As System.Drawing. Rectangle, ByVal [readOnly] As Boolean, ByVal instantText
As String, ByVal cellIsVisible As Boolean)

MyBase.Edit(sou rce, rowNum, bounds, [readOnly], instantText, cellIsVisible)

MyBase.TextBox. CharacterCasing = mccText

If mintMaxLength > 0 Then MyBase.TextBox. MaxLength = mintMaxLength

End Sub

Protected Overrides Function GetColumnValueA tRow(ByVal source As
System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer) As Object

Dim obj As String

Dim strReturn As String

obj = MyBase.GetColum nValueAtRow(sou rce, rowNum).ToStrin g

Select Case mccText

Case CharacterCasing .Lower

strReturn = obj.ToLower

Case CharacterCasing .Upper

strReturn = obj.ToUpper

Case CharacterCasing .Normal

strReturn = obj

End Select

If mintMaxLength > 0 And strReturn.Lengt h > mintMaxLength Then

strReturn = strReturn.Subst ring(0, mintMaxLength)

End If

Return strReturn

End Function

End Class

Ken

------------------------

"Aaron Smith" <th**********@s mithcentral.net > wrote in message
news:8l******** *********@newss vr16.news.prodi gy.com...
Is there a way to put a limit on the text size of a datagrid column?

Thanks,
Aaron

--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #5
Simply set DataGridTextBox Column.TextBox. MaxLength property in code
Nov 21 '05 #6
Simply set DataGridTextBox Column.TextBox. MaxLength property in code
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3360
by: Shravan Kumar | last post by:
Hi, I am using my code to set column widths of datagrid columns dynamically, but when I am setting the column widths to zero, the header text of the column whose width is made to zero is appearing on the existing column headers, and the text gets blurred with the painting of the column text along with the adjacent width 0 column. Anybody, can you please give me a solution for it
0
1824
by: Frnak McKenney | last post by:
One of the reasons given for the Allied victory in WWI is that the Nazi armament industry invested so much effort in creating new weapons (e.g. the jet plane) it wasn't able to develop any of them to the point of mass-production. There are days when I experience the same difficulties with C# and dotNET: there are twelve ways to do 'most _any_thing, and I wind up exploring six before I find an acceptable solution. <grin> Case in...
3
2521
by: Ben | last post by:
Hi, I'm wondering how can i change the datagrid header text at runtime so that it keeps the sorting enabled? I can do; e.Item.Cells.Text = "foo"; But then foo is the text of the table cell and not the underlying hyperlink and as such, foo is no longer sortable.
2
1595
by: martin | last post by:
Hi, I am iterating through the dataitems in a datagrid and producing and xml document, If a particular cell in the datagrid has a textbox control or a datagrid control in it then I have no problem retrieveing it value by casting with CTYPE however when the datagrid cell contains no control, but does contain text, then I am having great trouble accessing its value.
2
2376
by: JenHu | last post by:
hi, I have a datagrid in my asp.net application, I am using vb.net language. I want to have my last column as a link column, link to text file. The link path is "c:\Temp\" & F_File_Name, which is the 2nd column. For example, the data grid should like this:
19
3559
by: Joe | last post by:
I have an aspx page (referred to here as page_1) with a datagrid whose first column contains hyperlinks. When a user clicks one of these hyperlinks, he will navigate to another aspx page (referred to here as page_2). I need to cache the value of the link's text (hyperlink.text property) so that I can use it in the page_load event of page_2. I've thought of using a hidden field and then calling Request.Form("hdnClickedLinkText") in the...
0
296
by: Aaron Smith | last post by:
Is there a way to put a limit on the text size of a datagrid column? Thanks, Aaron -- --- Aaron Smith Remove -1- to E-Mail me. Spam Sucks.
4
10506
by: Melson | last post by:
Hi I've a problem. Can anyone help. I would like to use datagrid for data entry. How can I set the number of rows in the datagrid. And use the datagrid to update the ms sql table. regards melson
0
2728
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only, cannot serch by combine 3 table) Example I have the query table below, how do I make the code to seach based on the query from this: SELECT Product.ID, Product.Description, Quantity.Quantity, Quantity.SeialNo, Quantity.SupplierID,...
0
9595
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9432
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8891
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7420
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.