Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Datagrid Column Widths


I am using a datgrid, and looking for a way to "autosize" the column widths. Is this possible, or do I need to know the lenth of my data in order to set the column width?

Thanks




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Autosize DataGrid Column Widths
Is there a way to autosize the coulumn widths of a datagrid?

Maintaining DataGrid Column Widths On Refresh
When 'refreshing' a largely wizard generated form, the datagrid columns return to the 'default' sizes. What would be the 'best practices' way to restore them/maintain them to what they were before the refresh?



Should 'column widths' be stored as part of user settings?
For example, I maintain window width and height as part of user settings (via database), should the column widths be stored in the same manner? Or is there a good reason to NOT store them?

CB.NET DataGrid - Stopping Users Changing Column Widths
I have a VB.NET 2003 application using datagrids and need to stop usersfrom
changing the widths of columns by grabbing header borders and draggingthem left or right.

I cant find any property that stops this.

Can anyone suggest a solution.

Rob

Resizing Column Widths In Datagrid Keeping All Visible
Hi,

How do I allow the user to resize column widths in a datagrid but not exceed the visible width of the datagrid? I also need the columns not move the current selected column to the left (causing all the other columns, to the left of that one, to disappear out of the visible window).

Thanx in advance,

Nilesh2



Edited by - Nilesh2 on 8/2/2003 8:05:10 AM

Column Widths ???
Hi,

How do I allow the user to resize column widths in a datagrid but not exceed the visible width of the datagrid? I also need the columns not move the current selected column to the left (causing all the other columns, to the left of that one, to disappear out of the visible window).

Thanx in advance for any suggestions/assistance,

Jungo

Specifying Column Widths?
Hi,

I have a data analysis program which outputs 8 rows and 20 columns of data into an excel file. However, I want to also provide the summary data on screen as well and I put a picture box and used the print command. The trouble is that only 14 columns of data fit in the picure box (window & picture box are maximised etc...). The space between the columns in the picture box are a bit too big so all i need to do is specify a smaller width between columns if that's possible. Here's the code that writes the data to the picture box.

PicSummary.Print "Summary"
For r = 1 To TotRun Step 1
PicSummary.Print r, 'no new line!
For i = 1 To 20 Step 1 'cycle through some bins

PicSummary.Print TotScore(r, i), 'no new line!
Next i
PicSummary.Print "|" 'new line!
Next r 'Loop the file

Anyone know?

Thanks in advance.
S.

Column Widths (VBA)
I have a spreadsheet with A:AA columns, for example, all with varying column widths. What I need to do in code is assign the current column widths to variable, then autofit the columns based on content and print, then be able to revert back to the original column widths. Any ideas? Some sort of array?

Pasting Column Widths?
I have a workbook with 15 sheets in it. One of these is called Produciton Profile. I have added a button to this which on pressing it will open a new workbook and paste the contents of this sheet into it and save it. All works EXCEPT the paste doesnt preserve the coloumn widths/heights of the origional. The following is my code.

ALSO I tried the line:

WScopy.Range("A1:H49").Copy Destination:=WSpaste.Range("A1:H49").PasteSpecial(xlColumnWidths, xlNone, False, False)

but xlColumnWidths seems to be wrong?

<vba>
Sub Button1_Click()
Dim WScopy As Worksheet

Dim WBpaste As Workbook
Dim WSpaste As Worksheet

Set WScopy = Worksheets("Production Profile")



Set WBpaste = Application.Workbooks.Add
Set WSpaste = WBpaste.Worksheets("Sheet1")

WScopy.Range("A1:H49").Copy Destination:=WSpaste.Range("A1:H49")

WBpaste.SaveAs ("t:profile" + Sheet13.Cells(1, 3) + ".xls")
End Sub
</vba>

Column Widths In A DBGrid
How do you set column widths in a data bound grid

MSFlexGrid Column Widths
Hi Guys,
Does anyone out there know how to get the column widths of a MSFlexGrid to resize themselves at run-time? Different columns need to be different sizes depending on how long the longest text for that particular column will be when displayed. Thanks in advance!

Column Widths In Listbox
This has been bugging me for quite a while, so how do you adjust the column widths in a list box? (Is it even possible?)


~MikeJ

Listbox Column Widths
Hi,

I have a list box that I populate from a listview using additem with vbtab's inbetween.

The problem I have is that if the text in a cell is long it pushes the next colomn over, and I would like to set column widths so this does not happen.

Ai am using
Dim tabs(7) As Long
     tabs(0) = 20
     tabs(1) = 50
     tabs(2) = 90
     tabs(3) = 199
     tabs(4) = 300
     tabs(5) = 330
     tabs(6) = 360

which only specify the starting position, I assume?

Can anyone please help

How To Set Column Widths For MS Flex Grid
I am using an MS Flex GRid to display data from a table. However I can not find any way to size the column widths so that no data is cut off.
Any ideas?

Kid

Locking ListView Column Widths
Hi
Is there a way of locking the width of a listview column so that the user cannot change it.

thank you in advance

Si

Setting Column Widths Of A ListBox
I am using the code below to set the width of columns in a ListBox on a UserForm in Excel. However, I get the error "Could not set the ColumnWidths property. Type mismatch". Any thoughts?

Code:
Private Sub UserForm_Initialize()
ThisWorkbook.Sheets("Sheet1").Activate
colCnt = 2
Set rng = ActiveSheet.UsedRange 'Range("A3:B25")
With ListBox1
.ColumnCount = colCnt
.RowSource = rng.Address
cw = ""
For c = 1 To .ColumnCount
cw = cw & rng.Columns(c).Width & ":"
Next c
.ColumnWidths = cw
.ListIndex = 0
End With
End Sub

Changing Column Widths In Excel ...
I am opening Excel from my application, and am trying to format a worksheet to meet my spec., but VBA instructions don't seem to work well within VB. Can anyone tell me how I would perform any of the following :

(i) Column Sizing, i.e. col A = 8.43, col B = 11.57 etc.

(ii) Removing "Sheet2" and "Sheet3"


Any help much appreciated.


Thanks in advance .....

Setting Column Widths In MSHFlexGrid's
Hi,

How do I set a column with in a MSHFlexGrid1?

Cheers

T.

Adjusting Column Widths In MSFlexGrid
How would I programmatically adjust the column widths to fit the sizes of column titles, when the MSFlexGrid is populated with data.

Thanks - Vinay

Saving Listview Column Order, Widths Etc.
Does anyone know how to query a listview to find the column order and size? After I change the order and size of the columns, I would like to be able to save this information somewhere so when I open it up the next time it is in the order that I changed it to. How would I query the listview to have it return this information, how could I store it for when I would log on next time and how would I reorder the listview after I have loaded it with data from the saved information? Any suggestions would be greatly appreciated.

Ray

Automatically Changing Column Widths In Flexgrids
hi

i've got a routine to copy data from a databse file to a flex grid, but in some cases the column is too narrow and only part of the text in the field can be viewed, which is a problem as i will then be printing this table of data.

whats the easiest way to adjust column widths so that all the text in each cell can be viewed?

thanks

DataGrids And Adjusting Column Widths After A Query
I run a query using a command button on a form. The results of the query are used to populate a datagrid. I want to set the width of a specific column. Here is my code. Here is the code I think I need. I am not sure what to set it = to.


Code:

DataGrid1.columns(8).Width = ??



Also, I use the first field from DataGrid1 to populate data in DataGrid2 when it is clicked on. How can I always select the first column's value regardless of what field is clicked in that row?



Code:

Public Function ProjectTracking(strQSQL)
strSQL = "Select PT_NUM,NVL(CUSTOMER,'NA') as CUSTOMER,Cast(DUE_DATE as DATE ANSI) as DUE_DATE,Cast(REQUEST_DATE as DATE ANSI) as REQUEST_DATE,Cast(COMPLETED_DATE as DATE ANSI) as COMPLETED_DATE,REQUESTER,SUBMITTER,DESCRIPTION from PROJECT_TRACKING" & " " & strQSQL
searchRS.Source = strSQL
searchRS.CursorLocation = adUseClient
searchRS.CursorType = adOpenForwardOnly
searchRS.ActiveConnection = totalConn
searchRS.Open

If searchRS.EOF <> True Then
DataGrid1.Visible = True
Set DataGrid1.DataSource = searchRS
DataGrid1.columns(8).Width = ??
Else
retval = MsgBox("No Match", vbOKOnly, "No Match")
End If
End Function

Setting Column Widths In A Grid Control
Using Visual Basic .net 2003

How do I set column widths of a GridControl when a form loads?

Thanks for any assistance

Byron

Setting Variable Column Widths At Design Time
Trying to set column widths of a datagrip to different sizes at design. Able to set all columns to a certain width but would like to be able to vary the columns in the grid. HELP!!

Saving Array Of Grid Column Widths To Database?
I have an application which has an 2 ADO grids on a form into which multiple column databases are loaded. Whilst the application is running, the user can load different database tables into the grids. However, these tables will not all have the same number of columns (between 10 to 30 columns).

The user will nearly always want to modify the width of each column so that it looks good on screen but as each table is different, I am not able to predict what columns will be displayed.

So, what I want to do is allow the user to modify the column widths, the press a save button which will save the column widths in the database table so that the next time the user opens that table in the application, it recalls the columns widths previously saved, saving the user the tedious task of having to resize up to 30 columns every time they load that table.

I have an interim solution which saves the column widths to a dynamic array but this obviously loses the information when the application is closed.

Any suggestions?

Thank you.

Resizing Col Widths In Datagrid
Hi,

How do I resize column widths in a datagrid? I need them to be always fully visible and not move the current selected column to the left (causing all the other columns, to the left of that one, to disappear).


(i.e. DataGrid1.Columns.Item(3).Width =....etc)

Thanx in advance

Reeb

MSFlexGrid, Resize Event? For When You Resize Column Widths...
soz so many questions today

i need to make it so that when i resize one of the columns in the flexgrid it triggers an even to save the width of that column so it remembers it.

but there is no resize event, so how would i go about doing this? i have a feeling it probably wont be easy using the msFlexGrid....

How To Move The Cursor From One Column To Next Column In Datagrid
Hi
Everyone,    
    In Datagrid control, how the cursor move from one column to another column of the same row after updating the datagrid.
    plz anyone help me.
    
    thanking you in advance.

Add Column To Datagrid
Hi everybody; I hope one of you can help me.

I am displaying a table with a datagrid and want to add a column with the values from another table as it's contents.

Both tables have columns titled CODE. The second table has a field called TYPE that corresponds to the CODE (eg. CODE 101 means TYPE Maintenance). What I want to do is put the values of TYPE from the second table into the datagrid displaying the first table I'm not allowed to add a column into the table being displayed by the datagrid.

I'm connecting to the database thru Adodc (DISA for the first table; CODES for the second table)

I found this but when I try to populate the fields from the second Adodc (CODES) it doesn't work. I figure that's because the Datagrid1 is connected to DISA.

Private Sub AddColumn()
Dim c As Column
Set c = DataGrid1.Columns.Add(DataGrid1.Columns.Count)
With c
.Visible = True
.Width = 1000
.Caption = "type"
.DataField = CODES.Recordset.Fields("CODE").Name

'if i use .DataField = DISA.Recordset.Fields("WHATEVER").Name it
'puts the values from 'WHATEVER' into the column "type"

.Alignment = dbgRight
End With
DataGrid1.ReBind
End Sub

Any ideas?? Thanx in advance.

Set DataGrid.Column Value
Hi,

ive got a Problem with my data grid, i have a DataGrid where the Data Source is an DataEnvironment, allright it works, but now i want do add a column to that grid where i calculate fe: Column1 * Column2 but if i want to insert the value in the column with: DG.Columns(3).Value an error apears:

Column not found, |1

what have i to do to do that???

Column In Datagrid
Hi,
I have a datagrid that bind to a table. Some of the columns of the table are not editable. For those columns in the datagrid, I want to gray them out.
The datagrid property does not give enough tools for me to set up.

Please show me how.

Thank you,

Quang

Datagrid Column
On a form I have a datagrid...how do i specify the column width for each seperate column??

Datagrid Column
I don't want my identity column to show up in my datagrid. How do I control which columns I want visible and which ones I don't?

How To Add Column To Datagrid
Anyone know how to manually add a column to a datagrid.

The default value of the grid when you create the object is to only have two columns, I need 13. Thanks


Nightfox02

Datagrid Column Sum
I have a column in datagrid that displays all the prices. I want to sum up all the values from all the rows of that column and display it as a label. How can I sum up the data??

Thanks ... Bhavesh

Add Column To DataGrid
I am new to working with grids and cannot figure out how to add a column.
The grid is a DataGrid ActiveX Contol - Version 6.0. I can look at the
properties and code but cannot see where to add the column.

I appreciate your help.
Kevin

Add A Column In A Datagrid
I would like to know if it is possible to add a column in a datagrid.
I would like to have a column to describe all line in my datagrid.
By the way, is it possible to display a long text in the header on two line but in the same cell.
For example I have the text "this is my new cell"
And I would like that it display like that:
"this is my
new cell"
because I don't want that my columns have a width of 4000

Thanks in advance

How To Add A New Column Into A Datagrid ?
Hi,

I have a datagrid1 on my screen. I have a recordset myRst contains 3 fields (id, name, age). I set myRst as the datasource for my datagrid.
     set DataGrid1.datasource = myRst

Then I want to add a new column into this datagrid1, which can show info depend on the value of AGE. for example, if age < 12, show 'KID'; if 13 <= age <= 25, show 'Tenage'....
        
        DataGrid1.Columns.Add (3)
        DataGrid1.Columns(3).Width = 350
        DataGrid1.Refresh

Now i want to populate this new column using following code:

myRst.movefirst
do while myrst.eof = false
    with datagrid1
        if .columns(2).value < 12 then
            .columns(3).value = "kid"
        ......
        end if
    end with
    myrst.movenext
loop

When i ran the program, first 3 columns populuated successfully, but last column is empty, and I got following error:
        Column not found, /1

What does this mean?

 
Grace

How To Get The Column Name Of Datagrid
Is there anyone know how to get the number of columns and its corresponding name of datagrid and put it in list box or variable.

Or there's another option except datagrid which get the field name of a table.

Note: I only knew the name of the table but i dont know its field name.


Thank you very much for your reply.

Datagrid Column Sum
I am trying to find a way to sum the values of a column in my datagrid. I have not even found a way to isolate a single cell, row coordinate. Please help.

Datagrid Column Sum
I have a column in datagrid that displays all the prices. I want to sum up all the values from all the rows of that column and display it as a label. How can I sum up the data??

Thanks ... Bhavesh

Datagrid Column Sum
I have a column in datagrid that displays all the prices. I want to sum up all the values from all the rows of that column and display it as a label. How can I sum up the data??

Thanks ... Bhavesh

How Can I Get The Column Name Of The Datagrid
I want to get the name of the column when I double-click that column in a datagird control
how can i do it?
Thank u

DataGrid Column Width Value?
In this expression...

DataGrid.Columns.Item(iCol).Width = 1000

What type is '1000'?
Is it a Pixel, char...number.....etc....i cant figure it out......

the reason for this is I have a MSflex grid which has a column width of 20...i would like to know how to convert that number to the equiv in a datagrid..Please any help would be great. Thanks in advance

DataGrid Column Width Value
What is the Column Width Value Type.....ie... Pixels, Spaces, Points? etc...

Datagrid Column Control
I want to remove the column in my datagrid that shows the ID. How do you control which columns are visible?

Datagrid Column Width ????
I have two datagrids that are exactly the same. The only difference is that I am using them on different forms, and one of them has a filter.

My question is this.
On the first datagrid, I could write column widths like this
AppointmentsDataGrid.Columns("time").Width = 40
AppointmentsDataGrid.Columns("patient").Width = 150
AppointmentsDataGrid.Columns("Doctor").Width = 150
AppointmentsDataGrid.Columns("status").Width = 50
and the output was as I expected.

but then, on the second grid, when I write the same thing, the column widths get rediculously small. Is there a way of specifying the units used for the column widths that I have missed?

Jagdip

DataGrid - Format Of One Column
Set grdStock.DataSource = Adodc1
grdStock.Refresh
grdStock.Columns(0).Width = 900
grdStock.Columns(1).Width = 1700
grdStock.Columns(2).Width = 1700
grdStock.Columns(3).Width = 1700
grdStock.Columns(4).Width = 1700
rdStock.Columns(4).DataFormat = FormatCurrency(Price)

So I want to make column(4) with Format Currency. I tried this but does not work. Does anybody have idea how I can make this format in DataGrid?

Thanks,

Ilimax

Datagrid Column Question
I have a datagrid and would like all the cells in the first column to be "RECEIVE".
I've tried

DataGrid1.columns(0).text = "RECEIVE"

AND

DataGrid1.columns(0).value = "RECEIVE"

Neither worked

I was reading something about the DefaultValue property in my vb book that seems would work for my problem but ofcourse it has no examples. I also looked it up on the MSDN and it talks about using a Tag property, which I dont know how to use.

Setfocus To Datagrid Column
How can I set focus to a specific column in a datagrid

Copyright © 2005-08 www.BigResource.com, All rights reserved