473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Resize DataGridView column populated from DataSource

1
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 2517
Plater
7,872 Expert 4TB
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
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,...
5
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...
1
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...
3
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
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...
1
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...
0
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...
3
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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,...

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.