Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 19th, 2004, 09:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default Beginner's question re: WindowsForm DataGrid

I am trying to <b>programmatically</b> create a datagrid in a WindowsForm and then add specific
columns, from the dataset, to my datagrid without using the
right-click feature on the datagrid control from the form and setting up
the properties so that I can see how this works. I was able to BIND THE
DATASET TO THE GRID however I do not know how to add my columns. I treid
some code as indicated below to create my columns but I am still getting
the default of ALL COLUMNS being displayed in my datagrid.

<b>Any help or direction would be appreciated. Thank you.</b>

Within my FORM program, I am using the SEARCH BUTTON when clicked to do
the following:

private void btnInvoiceSearch_Click(object sender, System.EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;

<b>// Identify the variables from the form elements to pass to the stored</b>
procedure in the PSSBilling_WebService
int lintClientID = Convert.ToInt32(txtClientID.Text);
int lintMonth = lstMonthText.SelectedIndex + 1;
int lintYear = Convert.ToInt32(lstYearText.SelectedItem);

<b>// Create new instance of the InvoiceList class from InvoiceList.cs</b>
InvoiceList il = new InvoiceList(lintClientID, lintMonth, lintYear);

<b>// Display the count in the lblCount field.</b>
lblCount.Text = il.InvoiceCount.ToString();

<b>//bind the DataSet to the grid</b>
dataGrid1.SetDataBinding(il.InvoiceData, "ClientInvoices");

<b>//Define the columns to display.</b>
DataGridBoolColumn myDataCol1 = new DataGridBoolColumn();
myDataCol1.HeaderText = "Account No.";
myDataCol1.MappingName = "AccountNo";

DataGridBoolColumn myDataCol2 = new DataGridBoolColumn();
myDataCol2.HeaderText = "Client ID";
myDataCol2.MappingName = "Clientid";
}

From my InvoiceList.cs program I am using the following:

<b>// Constructor</b>
public InvoiceList(int aintClientID, int aintMonthText, int aintYearText)
{
iintClientid = aintClientID;
iintMonth = aintMonthText;
iintYear = aintYearText;

<b>// Connect to the PSSBilling_WebService</b>
PSSBilling.Service1 wsSearch = new PSSBilling.Service1();

<b>// Define the dataset for this class.</b>
idsInvoices = new DataSet();
idsInvoices = wsSearch.getInvoiceDataByClient( aintClientID,
aintMonthText, aintYearText );
}

<b>//Property created to Retrieve the count of the contents of the
constructor above.</b>
public int InvoiceCount
{
get
{
return idsInvoices.Tables[dsReturnedData].Rows.Count;
}
}

<b>//Property created to Retrieve the data of the contents of the
constructor above.</b>
public DataSet InvoiceData
{
get
{
return idsInvoices;
}
}
 
Old January 19th, 2004, 10:50 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The DataGrid.AutoGenerateColumns property needs to be set to false otherwise the grid will show all columns regardless of columns that you manually add.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old January 19th, 2004, 02:51 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default

Peter,

Thanks for your reply. However, I am working on a WindowsForm not a webform and consequently I do not show this property in my windowsform. Any other suggestions?

Thanks.

Quote:
quote:Originally posted by planoie
 The DataGrid.AutoGenerateColumns property needs to be set to false otherwise the grid will show all columns regardless of columns that you manually add.

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
A beginner's question Gene Reginato XSLT 5 May 17th, 2007 10:32 AM
Beginner's Question peytontodd Beginning VB 6 3 March 7th, 2007 11:58 AM
Help please: another beginner's question savoym C# 1 January 9th, 2004 11:45 AM
Beginner's question savoym C# 2 January 8th, 2004 03:58 PM
Beginner's SQL question pankaj_daga SQL Language 3 November 12th, 2003 07:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.