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;
}
}
|