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




(solved) Err... Datagrid Column


I wrote an small sub to autoresize the columns of my datagrid, but it has an little error... it doesn't work

What did i do wrong, when i run this vb will freeze and 30 seconds later it works again but nothing happend to my colums :/



VB Code:
Private Sub Command5_Click()On Error Resume NextDim StrSize As IntegerStrSize = 0 For i = 0 To dGrid.ApproxCount - 1          dGrid.Row = i     For J = 0 To dGrid.Columns.Count - 1    dGrid.Col = J        If TextWidth(dGrid.Text) > StrSize Then            StrSize = TextWidth(dGrid.Text)            dGrid.Columns(J).Width = StrSize        End If    Next Next End Sub




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Size Column In Datagrid By Code (SOLVED)
Hello,

In my app. I use this code to size my columns:

Me.Datagrid.Columns(2).Width = 2500

Now, the forms that are finished are having no problems, and it works perfect BUT any form I create from now on, this code doens't work..

very strange I think!

What could be the problem ?

tnx in advance....

nickname


!! The code to size the columns may not be followed by a refresh... !!

Catch The Colum Name From Column Value If Column Value = 0...help![solved]
hi guys...
a problem occured...hope u can give advice or soltion etc...

i have a table studdat

idStudent     [2/1/04] 'this is my coulmn name
8003    1
8004    1
8005    0
8006    1

the problem is...
 - i want to use the recordset .fields(j).name to catch the column name if my column value =0...but it wont...
   i just want to know if it is possible to do that or not...if it impossible then plz let me know....

eg code....

Code:If Not IsNull(.Fields(j).Value) Then
                    If j = 1 Then
                        If .Fields(j).Value = 1 Then 'select idclass from studdat where idStudent=...
                        MSFlexGrid1.TextMatrix(i, j) = "Hadir" '
                        ElseIf .Fields(j).Value = 0 Then
                        MSFlexGrid1.TextMatrix(i, j) = "Tidak Hadir"
        date=.Fields(j).name ' -------------------------------------------------->my codes have problem here
                        Else
                        MSFlexGrid1.TextMatrix(i, j) = "Tidak Hadir & Kenyataan"
                        End If
                    Else
                    MSFlexGrid1.TextMatrix(i, j) = .Fields(j).Value 'MASALAH KAT SINI
                    End If
                'End If
                ElseIf IsNull(.Fields(j).Value) Then
                    MSFlexGrid1.TextMatrix(i, j) = "No Record"
                End If
        

______________________________________________
Me And MySelf->The world are richer than we thought...
----------------------------------------------------------------

Edited by - Shatred on 1/5/2005 5:56:18 PM

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.

*solved*How Do I Get The Current Column Name In ADO T-SQL?
Hi All!

If Code:rs.Fields(0).Name returns the first column name

what would the current column name be in the current loop?

Taa..

---------------------------------------------------------------------------------------------------------------------------------
Todays random quote: I am still determined to be cheerful and happy, in whatever situation I may be; for I have also learned from experience that the greater part of our happiness or misery depends upon our dispositions, and not upon our circumstances.

Martha Washington (1732 - 1802)
---------------------------------------------------------------------------------------------------------------------------------

Edited by - Hopeless on 12/14/2005 2:44:03 AM

Adding Values In A Column [Solved]
How would i go about adding the values from a column in a database?
what controls, libs, ect do i need?

Thanks in advance



Edited by - dattas on 2/13/2004 6:34:50 PM

Select Statement By Column Help...[solved]
hi...
got a confusing problem here...
hope u guys can give me hint or advice....

i m using a flexgrid...with this select statement...i want to search a column by it name...
eg..
    the table contain [1/12/2004] as column header with its data...a user want to search for this column
    not by idStudent but by it own name...such...i search for date : 1/12/2004 and the flexgrid show all
    column [1/12/2004] and its data row by row...

could u help me guys by hitting me with some hint...i used to know to use select by id..but this time can i use select by
column name?.....

if u guys dont understand...please tell me so i can explain...
merry cristmast...

______________________________________________
Me And MySelf->The world are richer than we thought...
----------------------------------------------------------------

Edited by - Shatred on 12/26/2004 12:15:33 PM

Formatting A Column In Execl (SOLVED)
I have numbers stored in my array that i got from a text file.
Example:
tempArray(n).string1
tempArray(n).string2
tempArray(n).string3
tempArray(n).string4

My ArrayCompany function checks to see what is in the tempArray(n).string 3.



Code:
Public Sub ArrayCompany()
  Dim n As Integer
  n = 1
  'concateing 3 strings together for Company ID
  For n = 1 To UBound(tempArray)
  
  If (tempArray(n).string3 = "07") Or (tempArray(n).string3 = "08") Or (tempArray(n).string3 = "11") Then
    tempArray(n).string4 = tempArray(n).string3 + "-" + tempArray(n).string2
  Else
    tempArray(n).string4 = tempArray(n).string1 + "-" + tempArray(n).string3 + "-" + tempArray(n).string2
  End If
  Next
End Sub

The problem i get is if the tempArray(n).string3 is 07, 08, or 11 the tempArray(n).string4 is written like this: 07-1440, but when it gets dumped into Execl, execl writes it like a date: july/14/2040

if the tempArray(n).string3 IS NOT 07,08, or 11 it gets written like this: 01-011440 and gets writen into excel like that which is the way it is supposed to be.

is there a way in VB when I open execl I can format the whole column to be text so it does not write the date?
Code:
 xlWorkSheet.Columns.FormatCondition(Text)
  or
 xlWorkSheet.Cell.FormatCondition(Text)
 

no clue as you can tell

 

Edited by - epatterson78 on 12/9/2003 10:17:39 AM

Find A Text In An Excel Column...[solved]
here is my code


VB Code:
Dim CheckQAstr, CheckQAresult As StringDim CheckQAfile, CheckQActr As Integer CheckQActr = 5CheckQAfile = FreeFileOpen txtReportPath.Text & "vsapi.tmp" For Input As CheckQAfile DateStr = Format(Date, "mmm d")DiscrepancyApp.Workbooks.Open "p:-ProjectQALOGSHEETDCT QA Log.xls"Set DiscrepancyBook = DiscrepancyApp.Workbooks("DCT QA Log")With DiscrepancyBookSet DiscrepancySheet = DiscrepancyBook.Worksheets("Version 3.5")    With DiscrepancySheet        Do Until EOF(CheckQAfile)        Line Input #CheckQAfile, CheckQAstr        'dont know what code to place here        Loop    End WithEnd WithDiscrepancyApp.QuitClose #CheckQAfile


when i retrive CheckQAstr, i want to search it in column D of my excel worksheet.
could someone help me?
if the text is found, lets just write, debug.print "You found Me"
if not, lets just write, debug.print "Not Found"

.....

Error Handling Reading Column...[SOLVED]
hi guys...
got a problem on error handling...

can you take a look at my code....
i want to make error handling if the table dont have the specific column asked then it will return msgbox "please insert the correct date" instead of runtime error

If MyConnection.State = adStateOpen Then
         MyMainRecordset.Open "Select (idStudent),[" + name + "] from jan", MyConnection, adOpenStatic, adLockOptimistic
         MyMainRecordset2.Open "Select (idStudent),[" + name + "] from jan", MyConnection, adOpenStatic
    Else
         MsgBox "Unable to open database "
         MyConnection.Close
         Exit Sub
    End If

i have try to do it...just cant find the correct syntax...
can u help me?



Edited by - Shatred on 1/2/2005 2:14:57 AM

---Solved ---How To Set Text In MS FlexGrid Align To Left Or Right In Column ?
How to set data in MS FlexGrid align to left or right in each column ? Thanks

How To Filter Datetime Base Column In Rowfilter? (VB.NET) - SOLVED
Hi guys,

I need some help here.

I need to filter my dataview for certain date, I tried many method but it's seems not work. Is it date filter is not support in dataview rowfilter?

The command I had try are:

dv.rowfilter = "exchange_date = convert(datetime," & mydate.text & ",105)"
dv.rowfilter = "exchange_date = #" &mydate.text & "#"
dv.rowfilter = "exchange_date = " & ctype(mydate.text,date)

I also had tried change the mydate.text to '15-03-2004' also it's not work. Is it dv.rowfilter not supporting date filter in vb.net?
or there's work arround?

the solution is like

dv.rowfilter = "exchange_date = #" & format(cdate(mydate.text), "MM/dd/yyyy") & "#"

Appreciate your help

regards







Edited by - wisman on 3/15/2004 6:55:03 PM

Adding To DataGrid (NOT SOLVED)
i have a datagrid (DG)

i have 3 columns (value1, value2, value3) as the captions for the DG

i would like to add the array element values to column 2 ("value2")


VB Code:
for counter = 0 to ubound(arrValues)    dg.? = arrValues(counter)' this is where i am having problems of adding to the DGnext

PasswordChar In Datagrid SOLVED With Alternative
Hello,

I would like to know how you can fix a PasswordChar in a Datagrid by code?

example (I know this won't work)

Me.Datagrid.columns(7).text.PasswordCHar = "*"

Hope someone can help me...

tnx in advance !!

nickname

Datagrid Click Event <SOLVED>
is it possible that if i click a certain row in my datagrid, all the record on that row will be placed on its corresponding text box above it?

Datagrid Display[solved - Thanks To Rookie_student]
Finally got convinced with :

http://www.vbforums.com/showthread.p...716762#newpost


How do I get rid of the extra blank row and column displayed?
(See Attachment)

How To Populate A DataGrid By Variable Solved Thanks
Hello everybody,

removed !!


Thanks anyway





Edited by - hansb on 11/12/2003 1:24:51 PM

Datagrid Shows Nothing [SOLVED BUT STILL UNCLEAR]
Hi Guys,

  I swear I swear Iswear I have searched previous answers for ages before posting, but I really can't get my head around this.
I'm just trying to display an Access table into a datagrid control.
This is the code, part of a .bas Module in the project:

Code:
Dim DG As DataGrid
Set DG = DataViewData.DataGrid1
Dim cn As New ADODB.Connection
Dim RecordSet As New ADODB.RecordSet
Dim strSQL As String

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Test.mdb"
strSQL = "SELECT * FROM Labels"
Call RecordSet.Open(strSQL, cn, adOpenKeyset, adLockOptimistic)
RecordSet.MoveFirst
Set DG.DataSource = RecordSet
DG.Columns(0).Caption = "TEST"
DG.Refresh
MsgBox (RecordSet(3))
cn.Close


1) The MsgBox correctly shows the value of the fourth field in the first record --> the recordset is correctly loaded
2) The caption of the first column of the datagrid is correctly "TEST" --> the datagrid is working

WHY IS THE REST OF THE DATAGRID BLANK???? NO DATA, NO NOTHING???
It must be something so simple....

Thanks in advance

Aleporrino






Edited by - aleporrino on 7/5/2005 2:22:24 AM

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

Storing A DataGrid Record To A Textbox -SOLVED-
I want to allow the user to select a row from the datagrid and copy the individual fields of the selected record to individual textboxes for verification on the next screen.


Code:
Set conUDA = New ADODB.Connection
Set rsCust = New ADODB.Recordset
conUDA.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Persist Security Info=False;Data Source=" & App.Path & "UDA.mdb; mode = read"
        
conUDA.Open

strSQL = "select * from CUSTOMERS where FNAME Like '" & strFname & "' and LNAME Like '" & strLname & "' and COMPANY Like '" & strCname & "' and PHONE Like '" & strPhone & "'"

With rsCust
    .CursorLocation = adUseClient
    .Open strSQL, conUDA, adOpenDynamic, adLockOptimistic, adCmdText
End With


If rsCust.RecordCount = 0 Then
    MsgBox "No items found"
Else
    Set DataGrid1.DataSource = rsCust
    DataGrid1.Refresh
    
End If


After selecting the row and clicking next I want to transfer the selected fields to textboxes (as said above)...I am trying something like:

frmSession.txtFName.Text = DataGrid1.?????

Am I even close?






Edited by - melvijp on 12/7/2003 9:23:15 AM

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.

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

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

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

How To Set Datagrid Column To Uneditable
Hi. I have a form contains a datagrid (with 2 fields/columns: ID, UserName) and two command buttons ("Add", "View All"). When user clicks on "View All" button, the datagrid will display all the user information (ID 1 to 10) with the "ID" column/field is NOT editable. When the user clicks on the "Add" button, a new row (ID = 11) will be APPENDED as the last row in the current datagrid. In this case, user can add or modify this NEW appended Row (which mean ONLY the row with ID =11 is set to editable) while ID =1 to 10 is NOT editable also. I have use the following methods to make the new row(ID = 11) to editable but to no avail.

Any suggestion is truly appreciated.


Code:
'at form load
datagrid.column(0).locked = true

'when user clicks Add button
datagrid.CurrentCellModified = True
datagrid.EditActive = True

Datagrid Column Question???
Hi Guys,

I have a datagrid which has 5 column only and more than 500 rows. Now I want to Update only 4 th column I wrote update sql statement, but after updating the data I want to refresh only updated Row (other row should remain the same ) and cursor should go to next row on 4th column. Can anybody help me with this???

This is very urgent. please help me.........

Thanks in advance,
Ekta

Datagrid Column Sizing
I am trying to size the columns of a datagrid in VB6. I have placed a datagrid on a form and use

set r=new ador.recordset 'create disconected recordset

and

r.fields.append "col name", adVarChar, 500

to append columns.

There are currently 16 columns i use and no matter how i try i cannot get the columns to the size i want, each column needs to be a width that i specify. All columns seem to be of a size that i cannot determin the source of, its not the defCol widths or any value i can see any where else.

Any suggestions would be very much appreciated.

Datagrid Column Header
Hi all,
the text I have in my column header for my datagrid is too wide for the column width I am allowed. I have used vbCrlf to wrap the text but then I cannot see the second line in the column header row. Is there a way of setting the height of the column header row? Or alternatively is there a better solution to my problem? Any help would be greatly appreciated.

DataGrid Column Format
I want to format DataGrid column (type boolean) to display
'OK' for value 'True' and 'WRONG' for value 'False'.
DataSource is set in run-time mode as:

With DataGrid1
Set .DataSource=rst
End With

I can't format column in design-mode because there is no
column numer in Custom dialog for DataGrid1 properties.

Assign A Value To A Column In A Datagrid
This should really be easy.

I have a datagrid bound to a datasource. One of the column in the datagrid is not bound to a column in the datagrid.

I would like to assign a value, or be able to edit that column like so : grdDataGrid.Columns(3).Text = "Please Work"

Please see attached project (install in c: est1n).

Click on command1 to reproduce problem.

How To Add A Combobox For A Column In A Datagrid
Hi there..
How to add a combobox for a column in a datagrid or dbgrid ..for example in the access tables you can have a pull down list/menu..

The way i add a combobox for a datagrid or dbgrid is to add a separate combobox to the form....

if dbgrid/datagrid has column named product id, when the the user clicks on the column the combobox .left and .height and .top is set to the values of the datagrid.

what it does is it positions the combo box on top of the column in the datagrid.. unfortunately this is not a very easy way of doing..and it does not look good..

is there any other way for me to add a combo box to the datagrid.. doesnt the datagrid/dbgrid has a built in sort of combobox..

Thanking you guys in advance for helpig out..

regards pragash..

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