Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DataSet to fit DataGrid

Posted on 2006-07-19
7
Medium Priority
?
341 Views
Last Modified: 2008-03-06
Hi,

I load a dataset into a datagrid from XML file. The file loads correctly but its display doesn't completely fit the datagrid: there is a grey space on the right. I want to get rid of that grey space so that the data columns are expanded to use all of the space available. The first column, where you select the rows, shouldn't be expanded. How do I achieve this? I looked into DataGridTableStyle class but I couldn't figure out how to use it; it seems to repeat the same methods from DataGrid class. Thanks for your help.

 Private Sub Form1_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
        LoadXMLData()
    End Sub    

    Private Sub LoadXMLData()
        ds = New DataSet
        ds.ReadXml("c:\rules.xml")
        xmlRules.SetDataBinding(ds, "rule")
        tbl = ds.Tables(0)
    End Sub

XML file example
========

<?xml version="1.0"?>
<folder-rules>
  <rule>
    <variable>m_EDSTYPCD</variable>
    <value>P</value>
    <destination>Facilities</destination>
    <default>Blah</default>
    <function>PrintGreeting</function>
    <param1>Hello</param1>
    <param2>World</param2>
    <level>1</level>
  </rule>
</folder-rules>
0
Comment
Question by:njava
  • 2
  • 2
7 Comments
 
LVL 1

Author Comment

by:njava
ID: 17140604
xmlRules is a DataGrid
ds is a DataSet
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17141403
1) Define a DataGridTableStyle
2) Specify each column type as DataGridTextBoxColumn, DataGridBoolColumn, etc.
3) Define the column widths as a percent of ClientSize.Width for the entire DataGrid.

Bob
0
 
LVL 1

Author Comment

by:njava
ID: 17141651
Would it be possible to provide an example?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 200 total points
ID: 17141708
Example:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21876101.html

Set column widths like this:

Column 1:  DataGrid1.ClientSize.Width * .25
Column 2:  DataGrid1.ClientSize.Width * .25
Column 3:  DataGrid1.ClientSize.Width * .25
Column 4:  DataGrid1.ClientSize.Width * .10
Column 5:  DataGrid1.ClientSize.Width * .5
Column 6:  DataGrid1.ClientSize.Width * .20

The total needs to be 1.00 or 100% of the width.

Bob
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Loops Section Overview
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question