Results 1 to 9 of 9

Thread: Align-Right text in DataGrid's column

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

    Align-Right text in DataGrid's column

    How can i make the text inside a DataGrid's column align right? (default is align left)

    For your information, my DataGrid is mapped to a DataSource which is DistributeDataSet.
    Therefore I did not defined any tablestyle to the DataGrid in the design layout.
    So how can I use coding to set some of the columns in DataGrid agliment to right?

    please guide thank you.
    Last edited by albertlse; Jul 17th, 2003 at 09:04 PM.

  2. #2
    Addicted Member CoMMiE's Avatar
    Join Date
    Jul 2000
    Location
    Malaysia, Kuala Lumpur
    Posts
    179
    hi
    all you need to do is just set the texboxcolumn table style text alignment to right align
    To follow the path:
    look to the master,
    follow the master,
    walk with the master,
    see through the master,
    become the master.-ZEN

  3. #3

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163
    For your information, my DataGrid is mapped to a DataSource which is DistributeDataSet.
    Therefore I did not defined any tablestyle to the DataGrid in the design layout.
    So how can I use coding to set some of the columns in DataGrid agliment to right?
    please guide, thank you.

  4. #4
    Addicted Member CoMMiE's Avatar
    Join Date
    Jul 2000
    Location
    Malaysia, Kuala Lumpur
    Posts
    179
    Dim dgUnit_PriceColumnStyle As New DataGridTextBoxColumn()
    Dim dgGoodsOutTableStyle As New DataGridTableStyle()


    With dgLine_NOColumnStyle
    .Aignment =HorizontalAlignment.Right
    .MappingName = "Line_NO"
    .HeaderText = "Line No"
    .Width = 30
    .ReadOnly = True
    .NullText = vbNullString
    End With
    dgGoodsOutTableStyle.GridColumnStyles.Add(dgLine_NOColumnStyle)

    Datagrid1.TableStyles.Add(dgGoodsOutTableStyle)
    To follow the path:
    look to the master,
    follow the master,
    walk with the master,
    see through the master,
    become the master.-ZEN

  5. #5

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163
    what if i only want to apply the "align right" setting to only column 2, column 5, and column 7 of the DataGrid, not all columns? what should i do?

  6. #6
    Addicted Member CoMMiE's Avatar
    Join Date
    Jul 2000
    Location
    Malaysia, Kuala Lumpur
    Posts
    179
    the code i posted actually allow you to do that, for example if "Line_No" in the MappingName is actually col1 then the property that we set will only apply to that col and not all the col
    To follow the path:
    look to the master,
    follow the master,
    walk with the master,
    see through the master,
    become the master.-ZEN

  7. #7

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

    Question

    I still cannot managed to do it. I followed ur guide but still fail...

    For your information, in the design layout, my DataGrid does not has any columns.
    My DataGrid's DataSource is mapped to a DataSet.
    So when the DataGrid is loaded, the DataGrid does not has any columns.
    The DataGrid will only display the columns once the DataSet is filled.

    So how should I set the alignment?

    Please guide thank you!

  8. #8
    Addicted Member CoMMiE's Avatar
    Join Date
    Jul 2000
    Location
    Malaysia, Kuala Lumpur
    Posts
    179
    hi
    can you please verify that the mapping name property of the DataGridTextBoxColumn is same as the datatable column in the dataset your are trying to map to?

    if all else fail, maybe you can post the code where you bind the datagrid to the dataset and we will see whats wrong from there
    To follow the path:
    look to the master,
    follow the master,
    walk with the master,
    see through the master,
    become the master.-ZEN

  9. #9

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163
    Please download the attachment for my coding...

    P/S: You may need to change the Database Connection path to link to the database.

    Select from combobox 1
    Then, select from combobox 2
    The DataGrid will be filled.

    I want to make the following columns to alignment right:
    1. Taken
    2. Return
    3. Sold
    4. NetPrice
    5. TotalPrice

    Hope you can help me with this.

    Please guide thank you.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width