473,770 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Resize DataGridView column populated from DataSource

1 New Member
I have a DataGridView populated from a DataSource with the code:
Expand|Select|Wrap|Line Numbers
  1.         Dim dt As New DataTable
  2.         dt.Columns.Add("Name")
  3.         dt.Columns.Add("Result")
  4.         Dim dr As DataRow
  5.         For i = 1 To 12
  6.             dr = dt.NewRow()
  7.             dr(0) = "Name " & i.ToString()
  8.             dr(1) = "Result " & i.ToString()
  9.             dt.Rows.Add(dr)
  10.         Next
  11.         grd.DataSource = dt
  12.  
The grid is anchored so that it resized together with the form. I want to resize one of the columns when the grid resizes. I'm using the code:
Expand|Select|Wrap|Line Numbers
  1.     Private Sub grd_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grd.Resize
  2.         colName.Width = grd.Width - colResult.Width - 18
  3.     End Sub
  4.  
This has no effect (column is not resizing).

I have tested with populating the grid without a DataSource, using the code:
Expand|Select|Wrap|Line Numbers
  1.         For i = 1 To 12
  2.             n = grd.Rows.Add()
  3.             grd.Rows(n).Cells(0).Value = "Name" & i.ToString()
  4.             grd.Rows(n).Cells(1).Value = "Result" & i.ToString()
  5.         Next
  6.  
In this case, resizing works fine. However, I need to use a DataSource.

Could someone help ?
Oct 9 '09 #1
1 2539
Plater
7,872 Recognized Expert Expert
I always set my column autosizing to fit all cells (headers and regulars) and its always resized just fine?
Oct 9 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
8815
by: John Sidney-Woollett | last post by:
Is it possible to alter a table to resize a varchar column? The PG docs indicate lots of uses for "alter table T alter column C..." but not one that allows the changing of the type (or same type, new size). This is possible in Oracle (provided you are increasing the column size). Is there a way to resize the column without having to drop or recreate the table or column? Thanks
5
21461
by: bob | last post by:
Now this ought to be a simple matter. But nothing's simple in the Net world, I'm finding. In vb6 you could use "!" to force text to upper case in the format function. I've searched the vb.net help system and can't find any help on formatting text. There's plenty of help formatting numbers, dates, and times, though. I'm in the phase of converting from 6 to Net and it seems that even the simplest thing is very, very complicated. And it...
1
6808
by: martin1 | last post by:
Hi, All, DataGridView is populated with all coumns from database since i need some columns data for condition statement, after that I want to show rest of column in the DataGridView, so how to filter DataGridView column in order to show whatever column i want? Thanks
3
12862
by: martin1 | last post by:
All, ..Net 2.0 DataGridView column sort is automatic, I don't want column sort, is anybody know how to not sort column in DataGridView? Thanks
0
2376
by: Mike | last post by:
Hey everyone... I've got three problems with a custom DataGridView column I've built following the "How To: Host Controls in Windows Forms DataGridView Cells" article. The base editing control is a ComboBox which is similar to the built-in Combo column but will hopefully be more flexible. First: I am using this control in multiple columns which _should_ hold unique items. However, the items added to column A are visible in
1
2911
by: Chalkie | last post by:
Hello, I've hit what appears to be a serious problem with an unbound datagridview control that Ive added to a VB.Net program. Inadvertently I named one column 'Name' and a second 'Size'. The designer allowed me to do it but when I came to run the program the designer reported an error and looking at the error messages it it confusing the datagridview column with the form on which the control resides. I can't delete the datagridviw because...
0
1748
by: sk27ahmed | last post by:
Hi Any one can show me how to access datagridview column value on column checked unchecked. I create one column in datagridview of type checkbox,and on button click i write code to select all rows in the datagridview. The code for select all is for (int i = 0; i < dataGridView1.Rows.Count; i++) { dataGridView1.Rows.Cells.Value = true; }
3
6756
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I am wondering what is considered a best practice for setting column widths to fit the data for a DataGridView (.Net 2.0) that was created on-the-fly from an arbitrary query. What I would probably do is scan the width of each column for the first couple hundred or so rows and find the largest. (But how does one convert character counts to field widths in pixels?) More generally, however, is there a better approach to accomplish this?
0
2408
by: lenniekuah | last post by:
Hi Fellow Good Guys, I need your help, Please Help me. Surprising I encounterd another problem which never happened in VB.NET but in C# technique it causing problem. Here is the explanation : For testing purposes, Extract data from SQL SERVER NorthWind table Products to display ProductName and UnitPrice on DataGridView and also trying to have specific DataGridView ccolumn format to suit user requirements but it's not working. Here...
0
9617
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
9453
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,...
0
10254
Oralloy
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10036
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
9904
tracyyun
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8929
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
5354
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
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
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.