1) How do I make the contents of a Windows datagrid editable while at the
same time preventing new rows from being added?
2) How do I align the contents of a column align-right, but the header of
that same column align-left? 5 1136
Hi,
1) Dataset.tables( "MyTable").defa ultview.allowne w=false http://msdn.microsoft.com/library/de...ownewtopic.asp
2) you need to make your own column style for that. Here is an example of
one I wrote. Alignment is the header. Dataalignment is the grid cell.
Public Class HeaderAndDataAl ignColumn
Inherits DataGridTextBox Column
Private mTxtAlign As HorizontalAlign ment = HorizontalAlign ment.Left
Private mDrawTxt As New StringFormat
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. TextAlign = mTxtAlign
MyBase.TextBox. CharacterCasing = CharacterCasing .Upper
End Sub
Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing. Graphics,
ByVal bounds As System.Drawing. Rectangle, ByVal source As
System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal
backBrush As System.Drawing. Brush, ByVal foreBrush As System.Drawing. Brush,
ByVal alignToRight As Boolean)
'clear the cell
g.FillRectangle (backBrush, bounds)
'draw the value
Dim s As String = Me.GetColumnVal ueAtRow([source], rowNum).ToStrin g()
Dim r As Rectangle = bounds
r.Inflate(0, -1)
g.DrawString(s, MyBase.TextBox. Font, foreBrush, RectangleF.op_I mplicit(r), _
mDrawTxt)
End Sub
Public Property DataAlignment() As HorizontalAlign ment
Get
Return mTxtAlign
End Get
Set(ByVal Value As HorizontalAlign ment)
mTxtAlign = Value
If mTxtAlign = HorizontalAlign ment.Center Then
mDrawTxt.Alignm ent = StringAlignment .Center
ElseIf mTxtAlign = HorizontalAlign ment.Right Then
mDrawTxt.Alignm ent = StringAlignment .Far
Else
mDrawTxt.Alignm ent = StringAlignment .Near
End If
End Set
End Property
End Class
Ken
--------------------------------
"EdB" <Ed*@discussion s.microsoft.com > wrote in message
news:CF******** *************** ***********@mic rosoft.com...
1) How do I make the contents of a Windows datagrid editable while at the
same time preventing new rows from being added?
2) How do I align the contents of a column align-right, but the header of
that same column align-left?
I tried to understand you example but couldn't see how the header was
aligned, only appears as if the data was aligned. Would appreciate some
insight on how the header gets aligned to "alignment" in the example.
"Ken Tucker [MVP]" wrote: Hi,
1) Dataset.tables( "MyTable").defa ultview.allowne w=false http://msdn.microsoft.com/library/de...ownewtopic.asp
2) you need to make your own column style for that. Here is an example of one I wrote. Alignment is the header. Dataalignment is the grid cell.
Public Class HeaderAndDataAl ignColumn
Inherits DataGridTextBox Column
Private mTxtAlign As HorizontalAlign ment = HorizontalAlign ment.Left
Private mDrawTxt As New StringFormat
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. TextAlign = mTxtAlign
MyBase.TextBox. CharacterCasing = CharacterCasing .Upper
End Sub
Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing. Graphics, ByVal bounds As System.Drawing. Rectangle, ByVal source As System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal backBrush As System.Drawing. Brush, ByVal foreBrush As System.Drawing. Brush, ByVal alignToRight As Boolean)
'clear the cell
g.FillRectangle (backBrush, bounds)
'draw the value
Dim s As String = Me.GetColumnVal ueAtRow([source], rowNum).ToStrin g()
Dim r As Rectangle = bounds
r.Inflate(0, -1)
g.DrawString(s, MyBase.TextBox. Font, foreBrush, RectangleF.op_I mplicit(r), _
mDrawTxt)
End Sub
Public Property DataAlignment() As HorizontalAlign ment
Get
Return mTxtAlign
End Get
Set(ByVal Value As HorizontalAlign ment)
mTxtAlign = Value
If mTxtAlign = HorizontalAlign ment.Center Then
mDrawTxt.Alignm ent = StringAlignment .Center
ElseIf mTxtAlign = HorizontalAlign ment.Right Then
mDrawTxt.Alignm ent = StringAlignment .Far
Else
mDrawTxt.Alignm ent = StringAlignment .Near
End If
End Set
End Property
End Class
Ken -------------------------------- "EdB" <Ed*@discussion s.microsoft.com > wrote in message news:CF******** *************** ***********@mic rosoft.com... 1) How do I make the contents of a Windows datagrid editable while at the same time preventing new rows from being added?
2) How do I align the contents of a column align-right, but the header of that same column align-left?
Hi,
Here is an example http://www.onteorasoftware.com/downl...todatagrid.zip
Ken
------------------
"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:76******** *************** ***********@mic rosoft.com...
I tried to understand you example but couldn't see how the header was
aligned, only appears as if the data was aligned. Would appreciate some
insight on how the header gets aligned to "alignment" in the example.
"Ken Tucker [MVP]" wrote: Hi,
1) Dataset.tables( "MyTable").defa ultview.allowne w=false http://msdn.microsoft.com/library/de...ownewtopic.asp
2) you need to make your own column style for that. Here is an example of one I wrote. Alignment is the header. Dataalignment is the grid cell.
Public Class HeaderAndDataAl ignColumn
Inherits DataGridTextBox Column
Private mTxtAlign As HorizontalAlign ment = HorizontalAlign ment.Left
Private mDrawTxt As New StringFormat
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. TextAlign = mTxtAlign
MyBase.TextBox. CharacterCasing = CharacterCasing .Upper
End Sub
Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing. Graphics, ByVal bounds As System.Drawing. Rectangle, ByVal source As System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal backBrush As System.Drawing. Brush, ByVal foreBrush As System.Drawing. Brush, ByVal alignToRight As Boolean)
'clear the cell
g.FillRectangle (backBrush, bounds)
'draw the value
Dim s As String = Me.GetColumnVal ueAtRow([source], rowNum).ToStrin g()
Dim r As Rectangle = bounds
r.Inflate(0, -1)
g.DrawString(s, MyBase.TextBox. Font, foreBrush, RectangleF.op_I mplicit(r), _
mDrawTxt)
End Sub
Public Property DataAlignment() As HorizontalAlign ment
Get
Return mTxtAlign
End Get
Set(ByVal Value As HorizontalAlign ment)
mTxtAlign = Value
If mTxtAlign = HorizontalAlign ment.Center Then
mDrawTxt.Alignm ent = StringAlignment .Center
ElseIf mTxtAlign = HorizontalAlign ment.Right Then
mDrawTxt.Alignm ent = StringAlignment .Far
Else
mDrawTxt.Alignm ent = StringAlignment .Near
End If
End Set
End Property
End Class
Ken -------------------------------- "EdB" <Ed*@discussion s.microsoft.com > wrote in message news:CF******** *************** ***********@mic rosoft.com... 1) How do I make the contents of a Windows datagrid editable while at the same time preventing new rows from being added?
2) How do I align the contents of a column align-right, but the header of that same column align-left?
Ken,
If you use your code, the column does not retain it's format. Setting
col.Format = "n0" has no affect on the column. Any ideas?
"Ken Tucker [MVP]" wrote: Hi,
Here is an example http://www.onteorasoftware.com/downl...todatagrid.zip
Ken ------------------ "Dennis" <De****@discuss ions.microsoft. com> wrote in message news:76******** *************** ***********@mic rosoft.com... I tried to understand you example but couldn't see how the header was aligned, only appears as if the data was aligned. Would appreciate some insight on how the header gets aligned to "alignment" in the example.
"Ken Tucker [MVP]" wrote:
Hi,
1) Dataset.tables( "MyTable").defa ultview.allowne w=false http://msdn.microsoft.com/library/de...ownewtopic.asp
2) you need to make your own column style for that. Here is an example of one I wrote. Alignment is the header. Dataalignment is the grid cell.
Public Class HeaderAndDataAl ignColumn
Inherits DataGridTextBox Column
Private mTxtAlign As HorizontalAlign ment = HorizontalAlign ment.Left
Private mDrawTxt As New StringFormat
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. TextAlign = mTxtAlign
MyBase.TextBox. CharacterCasing = CharacterCasing .Upper
End Sub
Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing. Graphics, ByVal bounds As System.Drawing. Rectangle, ByVal source As System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal backBrush As System.Drawing. Brush, ByVal foreBrush As System.Drawing. Brush, ByVal alignToRight As Boolean)
'clear the cell
g.FillRectangle (backBrush, bounds)
'draw the value
Dim s As String = Me.GetColumnVal ueAtRow([source], rowNum).ToStrin g()
Dim r As Rectangle = bounds
r.Inflate(0, -1)
g.DrawString(s, MyBase.TextBox. Font, foreBrush, RectangleF.op_I mplicit(r), _
mDrawTxt)
End Sub
Public Property DataAlignment() As HorizontalAlign ment
Get
Return mTxtAlign
End Get
Set(ByVal Value As HorizontalAlign ment)
mTxtAlign = Value
If mTxtAlign = HorizontalAlign ment.Center Then
mDrawTxt.Alignm ent = StringAlignment .Center
ElseIf mTxtAlign = HorizontalAlign ment.Right Then
mDrawTxt.Alignm ent = StringAlignment .Far
Else
mDrawTxt.Alignm ent = StringAlignment .Near
End If
End Set
End Property
End Class
Ken -------------------------------- "EdB" <Ed*@discussion s.microsoft.com > wrote in message news:CF******** *************** ***********@mic rosoft.com... 1) How do I make the contents of a Windows datagrid editable while at the same time preventing new rows from being added?
2) How do I align the contents of a column align-right, but the header of that same column align-left?
Hi,
Private Sub SetupGrid()
Dim ts As New DataGridTableSt yle
ts.MappingName = "ArrayList"
Dim colDescription As New MultiLineColumn
With colDescription
..MappingName = "Col2"
..HeaderText = "Descriptio n"
..Width = 180
End With
ts.GridLineColo r = Color.Red
ts.GridLineStyl e = DataGridLineSty le.Solid
Dim cm As CurrencyManager = CType(Me.Bindin gContext(DataGr id1.DataSource) ,
CurrencyManager )
Dim pd As System.Componen tModel.Property Descriptor =
cm.GetItemPrope rties()("Qty")
Dim ni As New System.Globaliz ation.NumberFor matInfo
ni.NumberDecima lDigits = 3
Dim colQty As New DataGridTextBox Column(pd, "f")
With colQty
..MappingName = "Col1"
..HeaderText = "Qty"
..Width = 75
..FormatInfo = ni
End With
Dim collink As New HyperLinkColumn
With collink
..MappingName = "LinkColumn "
..HeaderText = "Link"
..Width = 150
End With
ts.GridColumnSt yles.Add(colDes cription)
ts.GridColumnSt yles.Add(colQty )
ts.GridColumnSt yles.Add(collin k)
DataGrid1.Table Styles.Add(ts)
ts = Nothing
colQty = Nothing
colDescription = Nothing
End Sub
Ken
-----------------------
"blue_nirva na" <bl*********@di scussions.micro soft.com> wrote in message
news:E0******** *************** ***********@mic rosoft.com...
Ken,
If you use your code, the column does not retain it's format. Setting
col.Format = "n0" has no affect on the column. Any ideas?
"Ken Tucker [MVP]" wrote: Hi,
Here is an example http://www.onteorasoftware.com/downl...todatagrid.zip
Ken ------------------ "Dennis" <De****@discuss ions.microsoft. com> wrote in message news:76******** *************** ***********@mic rosoft.com... I tried to understand you example but couldn't see how the header was aligned, only appears as if the data was aligned. Would appreciate some insight on how the header gets aligned to "alignment" in the example.
"Ken Tucker [MVP]" wrote:
Hi,
1) Dataset.tables( "MyTable").defa ultview.allowne w=false http://msdn.microsoft.com/library/de...ownewtopic.asp
2) you need to make your own column style for that. Here is an example of one I wrote. Alignment is the header. Dataalignment is the grid cell.
Public Class HeaderAndDataAl ignColumn
Inherits DataGridTextBox Column
Private mTxtAlign As HorizontalAlign ment = HorizontalAlign ment.Left
Private mDrawTxt As New StringFormat
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. TextAlign = mTxtAlign
MyBase.TextBox. CharacterCasing = CharacterCasing .Upper
End Sub
Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing. Graphics, ByVal bounds As System.Drawing. Rectangle, ByVal source As System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal backBrush As System.Drawing. Brush, ByVal foreBrush As System.Drawing. Brush, ByVal alignToRight As Boolean)
'clear the cell
g.FillRectangle (backBrush, bounds)
'draw the value
Dim s As String = Me.GetColumnVal ueAtRow([source], rowNum).ToStrin g()
Dim r As Rectangle = bounds
r.Inflate(0, -1)
g.DrawString(s, MyBase.TextBox. Font, foreBrush, RectangleF.op_I mplicit(r), _
mDrawTxt)
End Sub
Public Property DataAlignment() As HorizontalAlign ment
Get
Return mTxtAlign
End Get
Set(ByVal Value As HorizontalAlign ment)
mTxtAlign = Value
If mTxtAlign = HorizontalAlign ment.Center Then
mDrawTxt.Alignm ent = StringAlignment .Center
ElseIf mTxtAlign = HorizontalAlign ment.Right Then
mDrawTxt.Alignm ent = StringAlignment .Far
Else
mDrawTxt.Alignm ent = StringAlignment .Near
End If
End Set
End Property
End Class
Ken -------------------------------- "EdB" <Ed*@discussion s.microsoft.com > wrote in message news:CF******** *************** ***********@mic rosoft.com... 1) How do I make the contents of a Windows datagrid editable while at the same time preventing new rows from being added?
2) How do I align the contents of a column align-right, but the header of that same column align-left? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dmitry Akselrod |
last post by:
Hi,
I am using a standard .NET 1.0 Datagrid. Actually, I am using two, bound to
a master-detail relationship. Both DataGrids are bound to a datasource. I
have the MSDN version of the DateTime picker functioning quite well in the
datagrid. I am also tracking a double-click event within another column in
the datagrid. The column is...
|
by: Matthew Wieder |
last post by:
Hi - I have a datagrid that has a black header and the rows alternate
white and gray. The problem is that until items are added to the grid,
the grid appears as a large black rectangle, which is quite ugly. The
black area is larger then it is once an item is added. How can I solve
this problem either by:
A) Having only the header black and...
|
by: VB Programmer |
last post by:
I have an ASP.NET form that allows people to answer survey questions. There
could be from 5 to an unlimited amt of questions, depending on which
questions the admin wants to users to answer (he sets it up previously).
The questions are in a db.
Is a datagrid the best way to display this data? What do you suggest?
After they enter the...
|
by: jy836 |
last post by:
1) When using images for an application (such as in an ImageList or as the
image for a button), are the images embedded in the application or must the
image files be included in the setup package?
2) Is there a way to adjust the individual column widths of a DataGrid which
has no TableStyles or GridColumnStyles? Also, is there a way to make...
|
by: JohnR |
last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a
datagridtablestyle defined. I use the datagridtablestyle to change the
order of the columns (so they can be different than the column order of the
datatable). I also allow the user to click on a column header to sort the
datagrid by that column.
I need to identify...
| |
by: melton9 |
last post by:
I'm just getting into using datagrid and have a couple of questions.
1.)How do you get the grid to show the values of a datatable
automatically? Currently I have to hit the + sign and then select
"getNews"(the datatable) to show my data.
2.) I have this set up to a loop. So after I view my grid any updates
in the loop causes the...
|
by: Newish |
last post by:
Hi
Couple of questions on datagrid
1) Is there a performance issue when using datagrid to display data
from a datatable.
2) Is there a security issue when using datagrid to display data from
a datatable and enable it to allow edits as well.
|
by: Tony Girgenti |
last post by:
Hello.
I'm developing and testing a web application using VS.NET 2003, VB, .NET
Framework 1.1.4322, ASP.NET 1.1.4322 and IIS5.1 on a WIN XP Pro, SP2
computer. I'm using a web form.
For a datagrid control, i used the Caption property. It displays fine on
the datagrid and allows me to run the program.
But, when i view the HTML for the...
|
by: rn5a |
last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB
table. Users can modify the records using this DataGrid for which I am
using EditCommandColumn in the DataGrid. This is the code:
<script runat="server">
Dim sqlConn As New SqlConnection(".....")
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not...
|
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...
|
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...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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...
|
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...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| |