473,756 Members | 3,499 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

2003 Datagrid and beyond

cj
I was looking over some of my 2003 code today (see below) that loads a
foxpro table via oledb connection.

I used a sub "autosizecolumn s" I found on the web but I never quite
understood why they said the style name had to be the same as the table
name. Perhaps the are refering to ts1.mappingname must be the same as
the table name (datagrid1.data member) because I've read that that is how
the datagrid associates a style with what it's displaying. Is that it?

Also, I can't figure out how I pulled off using
system.drawing. color.fromname( "info"). I think that was something I
came up with but it makes no sense now. Can someone enlighten me?

Lastly all this is probably a mute point now as I see we have a new
control in 2005 (datagridview). So I started typing in this code from
scratch in 2005 to see how it works. I got to datagrid1.setda tabinding
only to find it doesn't exist. How do I attach the datatable in the
dataset to the datagrid in 2005?

mySQLCommand.Co mmandText = fields & from & where & order
mySQLCommand.Co nnection = myFoxProConnect ion
myDataAdapter.S electCommand = mySQLCommand

myDataAdapter.F ill(ds, tableName)

DataGrid1.SetDa taBinding(ds, tableName)

Dim ts1 As New DataGridTableSt yle
ts1.ReadOnly = True
ts1.RowHeadersV isible = False
ts1.ColumnHeade rsVisible = False
ts1.Alternating BackColor = System.Drawing. Color.FromName( "info")
ts1.MappingName = DataGrid1.DataM ember
DataGrid1.Table Styles.Add(ts1)

AutoSizeColumns (DataGrid1)

' *************** *************** *************** *************
' Sizes all columns of a datagrid optimally.
'
' Parameters:
' TempDG - The datagrid that owns the column
' Notes:
' Ensure that a style exists for the table you are
' viewing and that the style name is the same as the table name.
' *************** *************** *************** *************
Public Sub AutoSizeColumns (ByRef TempDG As DataGrid)
Dim iCount As Integer
For iCount = 0 To (TempDG.Visible ColumnCount() - 1)
AutoSizeCol(iCo unt, TempDG)
Next
End Sub

' *************** *************** *************** *************
' Sizes a column of a single datagrid column optimally.
'
' Parameters:
' iCol - The column to resize
' TempDG - The datagrid that owns the column
' Notes:
' Make sure the column is a valid one. Also, ensure
' that a style exists for the table you are viewing and that
' the style name is the same as the table name.
' found on experts-exchange.com
' *************** *************** *************** *************
Public Sub AutoSizeCol(ByV al iCol As Integer, ByRef TempDG As DataGrid)
Dim iMaxWidth, iTemp As Integer
Dim iNumRows As Integer = TempDG.BindingC ontext(TempDG.D ataSource,
TempDG.DataMemb er).Count
Dim G As Graphics
Dim sf As StringFormat = New
StringFormat(St ringFormat.Gene ricTypographic)
Dim sTemp, sTableName As String
Dim Size As SizeF

' Get a graphics handle
G = Me.CreateGraphi cs

' Loop thru all rows of this column. Get length of longest string
If iNumRows 0 Then
For iTemp = 0 To (iNumRows - 1)
sTemp = TempDG(iTemp, iCol).ToString
Size = G.MeasureString (sTemp, TempDG.Font, 500, sf)
Size.Width += 10
If Size.Width iMaxWidth Then iMaxWidth = Size.Width
Next iTemp
End If

sTableName = TempDG.DataMemb er

' Lastly, consider length of column header name
sTemp =
TempDG.TableSty les(sTableName) .GridColumnStyl es(iCol).Header Text()
Size = G.MeasureString (sTemp, TempDG.Font, 500, sf)
Size.Width += 10
If Size.Width iMaxWidth Then iMaxWidth = Size.Width

' Modify the width of the grid column style
TempDG.TableSty les(sTableName) .GridColumnStyl es(iCol).Width = iMaxWidth
MsgBox("Width of Column " & iCol & " is " & iMaxWidth,
MsgBoxStyle.Inf ormation, "FYI")
G.Dispose()
End Sub
May 11 '07 #1
2 1776
Hi Cj,
but I never quite understood why they said the style name had to be the
same as the table name. Perhaps the are refering to ts1.mappingname must
be the same as the table name (datagrid1.data member)

Yes, you're right. If a DataGrid is bound to a datatable, and the name of
the datatable is the same as the MappingName of one of the
DataGridTableSt yle used by the DataGrid, this DataGridStyle is applied.
Also, I can't figure out how I pulled off using
system.drawing. color.fromname( "info").

FromName is a static method of the Color structure. This statement is to
return a color named 'Info'.
I got to datagrid1.setda tabinding only to find it doesn't exist. How
do I attach the datatable in the dataset to the datagrid in 2005?

Yes, DataGridView is a new WinForms control introduced in .NET 2.0, which
aims to replace and add functionality to the DataGrid control. DataGridView
doesn't has a method called SetDataBinding. To bind a DataGridView to a
data source, you should set the DataSource and DataMember properties of the
DataGridView. For example:

this.dataGridVi ew1.DataSource= this.dataset1;
this.dataGridVi ew1.DataMember ="DataTable1 ";

For more information on the differences between the DataGridView and
DataGrid controls, you may visit the following documentation:

'Differences Between the Windows Forms DataGridView and DataGrid Controls'
http://msdn2.microsoft.com/en-us/library/ms171628.aspx

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

May 14 '07 #2
cj
Thanks Linda

Linda Liu [MSFT] wrote:
Hi Cj,
>but I never quite understood why they said the style name had to be the
same as the table name. Perhaps the are refering to ts1.mappingname must
be the same as the table name (datagrid1.data member)

Yes, you're right. If a DataGrid is bound to a datatable, and the name of
the datatable is the same as the MappingName of one of the
DataGridTableSt yle used by the DataGrid, this DataGridStyle is applied.
>Also, I can't figure out how I pulled off using
system.drawing. color.fromname( "info").

FromName is a static method of the Color structure. This statement is to
return a color named 'Info'.
> I got to datagrid1.setda tabinding only to find it doesn't exist. How
do I attach the datatable in the dataset to the datagrid in 2005?

Yes, DataGridView is a new WinForms control introduced in .NET 2.0, which
aims to replace and add functionality to the DataGrid control. DataGridView
doesn't has a method called SetDataBinding. To bind a DataGridView to a
data source, you should set the DataSource and DataMember properties of the
DataGridView. For example:

this.dataGridVi ew1.DataSource= this.dataset1;
this.dataGridVi ew1.DataMember ="DataTable1 ";

For more information on the differences between the DataGridView and
DataGrid controls, you may visit the following documentation:

'Differences Between the Windows Forms DataGridView and DataGrid Controls'
http://msdn2.microsoft.com/en-us/library/ms171628.aspx

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.
May 14 '07 #3

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

Similar topics

3
4864
by: PeterZ | last post by:
Hi, In a running C# app with a datagrid control I select all rows in the dataGrid using CTRL-A, I then paste into some other app like notepad or Word but the column headings get left off. Is there any way of including column headings when copying/pasting from a running datagrid to notepad? At this stage it looks like I have to write my own code but would rather not if someone knows how to do it.
1
1516
by: Michael Gorbach | last post by:
Iv got a StatisticsContainer object that contains an arraylist of objects of different types, all inherited from class Statistic. The statistics class has 2 string public properties, name and stringValue. The classes that inherit from it use those two properties, plus several properties of their own of types double and vector. I need to display this StatisticsContainer class on a datagrid, but I'm having problems because each of the...
15
9185
by: Rik Brooks | last post by:
I find it amazing that I am quickly able to find answers to obscure questions but simple ones elude me. I have a datagrid that I've bound, no problem at all. Now I want to - programatically - loop through each row, extracting the data held in each column. I can't figure out how to do that. It has to be simple, can somebody please help me? --
8
1956
by: Inigo Jimenez | last post by:
I have an ASP .net web application installed in a Windows 2003 server. This web application has a webform that has a Datagrid. This Datagrid is filled with the data of a SQL table. I have a button that inserts a new row in the SQL table and then refresh the datagrid.
0
1700
by: optimizeit | last post by:
What I am attempting to do is import an Excel Workbook and display the worksheets in a datagrid dynamically. I am very close to getting this to work. I have to this point successfully imported a single worksheet into a dataset. I successfully built a dynamic datagrid. And I did successfully bind it to the dataset. Then I added the datagrid control to a PlaceHolder. The first worksheet displays beautifully. The next step is to allow...
2
1959
by: charliewest | last post by:
I am dynamically creating my datagrid, building each column in real-time via code-behind (using c#). The only way i have read to add ImageButtons to my grid dynamically is by creating a separate template class. However, a class cannot create server controls (or at least this is beyond me). I am able to create HTML <INPUT> form elements, however, these are not wired to my datagrid and hence, when clicked do not fire the datagrid's...
3
2326
by: Richard | last post by:
In ASP.NET 1.1, I have SmartNavigation turned on so that the user's focus will remain on the line in the datagrid they choose to edit. When the user chooses to add a new line in the datagrid, rather than only show that line, I'm displaying all items in the datagrid, with the new line at the bottom. With grdResults ' Set editing on last row .EditItemIndex = .Items.Count .DataSource = ds
3
1089
by: OhWhite | last post by:
In an off-line Vb.net 2003 application, is there any reason why the following would happen. 1) Minimize button doesn't function. 2) Button and DataGrid widen beyond Design time settings. Thanks
0
9456
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
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9841
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
8712
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...
0
6534
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
5141
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...
0
5303
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
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.