|
Hi All,
I'm kind of new to C# and I have a datagrid question. I have a master-detail form with databound controls. The selection is made by a combo box containing a list of all customers. There are then some databound text boxes with customer fields. And finally there is a data grid with a list of notes for the particular customer. To get all this to work together, I used the data table (customerDS.Customer) as the datasource for all controls. The individual fields are then the data members. For the grid, the Customers table is the datasource and the relation (Customer_CustomerNote) is the data member.
What I'm having trouble with is setting up TableStyles and ColumnStyles. I would like to change column widths, column headings, etc. on the grid. But even if I set up the TableStyles and ColumnStyles the way I want, the grid still displays as the default (i.e. all columns, field names from my dataset as column headings, etc.). For the Mapping Name for my TableStyle I use the data relation (Customer_CustomerNote) - it's the only choice in the dropdown list anyway. For Mapping Names for my ColumnStyles I drill down to Customer_CustomerNote --> (Individual field names).
If someone has any insight as to what I need to do or what I'm doing wrong I'd appreciate the help.
Thanks,
Dennis
|
|
|
|
|
Hi Dennis,
Whats the problem you are having. Can you try using the following code.
DataGridTableStyle tsstyle = new DataGridTableStyle();
tsstyle.MappingName = dataGrid1.DataSource.ToString();
dataGrid1.TableStyles.Add(tsstyle);
Console.WriteLine(dataGrid1.TableStyles[0].GridColumnStyles.Count.ToString());
dataGrid1.TableStyles[0].GridColumnStyles[0].HeaderText = "User Id";
dataGrid1.TableStyles[0].GridColumnStyles[1].HeaderText = "User First Name";
dataGrid1.TableStyles[0].GridColumnStyles[2].HeaderText = "User Last Name";
dataGrid1.TableStyles[0].GridColumnStyles[3].HeaderText = "User Age";
Hope this will help you.
Thanks
SGS
|
|
|
|
|
Thanks for your reply Kodanda.
I tried your code. Here are the results:
I wasn't sure whether you wanted me to use the above code with all my designer settings still in place or use the above code instead of setting everything up through the designer. If I kept my settings in place, the additional TableStyle you create in your code never gets used. But if I remove my settings, it appears there is no mechanism in the above code to attach ColumnStyles to the TableStyle before accessing the ColumnStyles. I tried both ways.
If I added the code above with everything set up in the designer as I had before (i.e. my TableStyle and all ColumnStyles still set up) I was able to access 3 GridColumnStyle indices (0, 1, and 2). This, I assume, is because I set up 3 ColumnStyles via the designer. If I tried to access a fourth index (there are actually 5 fields in the dataset) I got an array out of bounds exception. When I run the code, the Console.WriteLine tells me there are 3 ColumnStyles. All of this makes sense to me. But the grid still appears in my form (both in the designer and at runtime) with all 5 columns from the dataset (instead of just the 3 I set up ColumnStyles for) and the default header names and widths.
If I removed my designer-created TableStyle and ColumnStyles and tried to use your code in its place, I got an array out of bounds exception at the access of GridColumnStyles[0] as I figured I would since there didn't seem to be any mechanism for attaching the ColumnStyles to the TableStyle. The only way I could find to attach them was basically using the same code the designer had used when it hooked up my visual settings. And the result was the same - the grid showed all 5 columns with default widths and heading names.
I am at a loss. Everything appears to be set up properly. I even looked through the designer-generated code and everything made sense. But somehow the grid is not displaying the way it's set up to. When I originally had the grid hooked up to an actual table for a datasource (instead of the Customer_CustomerNotes relation) my TableStyle and ColumnStyles seemed to work. Is there an issue with these working if you hook the grid up to a data relation instead of a data table? Or am I just missing something?
Thanks again,
Dennis
|
|
|
|
|
Hello,
I have a webservice method which reads a local file and returns the byte array. But when ever i run it from the client it throws \either a SOAP exception or authentication error. (I use Windows server 2003)I continue to recieve these errors despite the following actions
1) Gave Administrator rights to ASP.NEt user in windows
2) Added HttpGet and HttpGet elements to Web.Config
3) Allowed anonymous access alone in IIS, Anonymous access + windows authentication and then Windows authentication alone.
4) created a Network credential object and gave NT user account details.
Can anyone help me ? I just need to read a file from the machine where the service runs and return the byte array.
Thanks in advance and tnx for your time.
James Poulose
|
|
|
|
|
Check the physical file permissions. I doubt they're set to allow annonymous read/write. I'd also check IIS's settings. You can always use impersonation in your web.config file to force your code to run under a specific identity. You can do the same thing in code as well. Use a WindowsPrincipal object to get the same results.
|
|
|
|
|
How to create a shallow copy of List<t> ? It doesn't seem to implement the Clone method. Is CopyTo the same ?
Best regards, Desmond
|
|
|
|
|
|
Hello:
From a web form I’m sending to execute a function contained into a class, code in web form is:
bool que = WUC_CreDes.Class1.Hay_PostBack(this, w1,w1cx, w1ID, w2, w2cx, w2ID);
In class code is:
public static bool Hay_PostBack(WUC_CreDes.WebForm1 parent1, string w1,
string w1cx,
string w1ID,
string w2,
string w2cx,
string w2ID)
{
string cual = "";
cual = HttpContext.Current.Session["par1"].ToString();
parent1.Example.Controls.Clear();
if(cual == w1)
{
Control control = parent1.Page.LoadControl(w1cx);
control.ID = w1ID;
parent1.Example.Controls.Add(control);
}
else
{
Control control = parent1.Page.LoadControl(w2cx);
control.ID = w2ID;
parent1.Example.Controls.Add(control);
}
return false;
}
As you can see, I’m sending to function container into class my WebForm1 to create in function WUC dynamically created.
Thinking in a second web form, let us say, WebForm2, if within it I send to execute my function:
bool que = WUC_CreDes.Class1.Hay_PostBack(this, w1,w1cx, w1ID, w2, w2cx, w2ID);
How can I do to function Hay_PostBack, above mentioned work also for WebForm2 What I need to change because first parameter is WUC_CreDes.Web Form1 parent1?
I’ll thank your answers.
Greetings.
A.L.
El hombre que tiene amigos debe mostrarse amigo...
|
|
|
|
|
Hey u raised the simplest inheritance question possible
All your windows forms in C# or .Net rather inherit from a common base class which System.Windows.Forms so whether u want to send webForm1 or webForm2 or .... webFormn u can do it passing it as a base class and then later converting it into the derived class and by performing a runtime check
I dont have the visual studio while writing this, so there might be some error in the code that I write in here but u will get a general idea
using System.Windows.Form;
public static bool Hay_PostBack(System.Windows.Forms.Form parent1, string w1,
string w1cx,
string w1ID,
string w2,
string w2cx,
string w2ID)
{
if(parent1.GetType().ToString() == "WUC_CreDes.WebForm1")
{
WUC_CreDes.WebForm1 frm = (WUC_CreDes.WebForm1)parent1;
if (frm!=null) frm.Do_Something();
}
else if (parent1.GetType().ToString() == "WUC_CreDes.WebForm2")
{
WUC_CreDes.WebForm2 frm = (WUC_CreDes.WebForm2)parent1;
if (frm != null) frm.Do_Something();
}
}
and there you are .... that should kinda solve your query .... if theres any problem with that one write me back .... Since I dont VS.Net right now there might be syntax errors in what I typed but if i finc some I ll key in another reply
Pushkar Pathak
|
|
|
|
|
Thanks you Pushkar:
I guess your code is right to window form, but I'm using web form.
What would be equivalent code in web form to
System.Windows.Forms.Form?
And how can I call Hay_PostBack from my web form?
maybe:
bool que = WUC_CreDes.Class1.Hay_PostBack(this, w1,w1cx, w1ID, w2, w2cx, w2ID);
Please help me.
El hombre que tiene amigos debe mostrarse amigo...
|
|
|
|
|
I’ve continued working on my code, it’s now thus:
public static bool Hay_PostBack(System.Web.UI.Page parent1, string w1,
string w1cx,
string w1ID,
string w2,
string w2cx,
string w2ID)
{
WUC_CreDes.WebForm1 frm1;
WUC_CreDes.WebForm2 frm2;
string fofoi = parent1.GetType().ToString();
if(fofoi == "ASP.WebForm1_aspx")
{
frm1 = (WUC_CreDes.WebForm1) parent1;
frm1.parent1.Example.Controls.Clear();
}
}
Yet in last line: frm1.parent1.Example.Controls.Clear();
It’s giving me error: WUC_CreDes.WebForm1' doesn’t contains a definition to 'parent1'.
Example is a place holder contening both in WebForm1 and in WebForm2.
I’ll thank your help.
A.L.
El hombre que tiene amigos debe mostrarse amigo...
|
|
|
|
|
Finally I found the solution:
To call function:
bool que = WUC_CreDes.Class1.Hay_PostBack(this, w1,w1cx, w1ID, w2, w2cx, w2ID);
The function:
public static bool Hay_PostBack(System.Web.UI.Page parent1, string w1,
string w1cx,
string w1ID,
string w2,
string w2cx,
string w2ID)
{
WUC_CreDes.WebForm1 frm1;
WUC_CreDes.WebForm2 frm2;
string cual = "";
cual = HttpContext.Current.Session["par1"].ToString();
string fofoi = parent1.GetType().ToString();
if(fofoi == "ASP.WebForm1_aspx")
{
frm1 = (WUC_CreDes.WebForm1) parent1;
frm1.Example.Controls.Clear();
if(cual == w1)
{
Control control = frm1.Page.LoadControl(w1cx);
control.ID = w1ID;
frm1.Example.Controls.Add(control);
}
else
{
Control control = frm1.Page.LoadControl(w2cx);
control.ID = w2ID;
frm1.Example.Controls.Add(control);
}
}
else
{
if(fofoi == "ASP.WebForm2_aspx")
{
frm2 = (WUC_CreDes.WebForm2) parent1;
frm2.Example.Controls.Clear();
if(cual == w1)
{
Control control = frm2.Page.LoadControl(w1cx);
control.ID = w1ID;
frm2.Example.Controls.Add(control);
}
else
{
Control control = frm2.Page.LoadControl(w2cx);
control.ID = w2ID;
frm2.Example.Controls.Add(control);
}
}
}
return false;
}
Greetings.
A.L.
El hombre que tiene amigos debe mostrarse amigo...
|
|
|
|
|
Hello all,
I have an application which runs as a windows service. When it starts up it processes a number of interfaces and sets up a timer for each of the interfaces using System.Timers timers.
If two interfaces are scheduled to run at exactly the same time the OnTimedEvent() method only gets called for one of the interfaces. If the interfaces are scheduled to run at different times everything runs fine.
As a test I knocked together a quick and dirty app using Threading.Timers and these work fine. However to re-write the service to use them would be a last resort. Also the .NET documentation recommends using the System.Timers when writing server apps etc
Does anybody know what I may be doing wrong? Or has anybody experienced a problem like this before, so I can at least tell my boss it is a known problem
Thanks
Simon
|
|
|
|
|
Try locking your method so only 1 thread can access it at any given time:
private void myTimerEvent(object sender, EventArgs e)
{
lock(this)
{
...
}
}
|
|
|
|
|
|
When a window form is working, I would like to show a small form just to tell users "Please wait...", but it seems that when the main form is working, the small form can not appear correctly. How to solve this?
|
|
|
|
|
Use a thread to display the child form
Have a wonderful evening
Doug Wright
Developer, TDCI
|
|
|
|
|
Can you teach me a little about this? I am not sure I know much of threading
|
|
|
|
|
Threading is a sure solution. But if it is possible to solve things in other way then avoid threading. Immediately before your "heavy" processing starts launch the new form and give a Application.DoEvents (In C#) This should solve your problem, or else you can go for a thread.
|
|
|
|
|
Hi all,
Anyone knows how to use pivot table in .net(c#)
It works well in vb but it is not working in .net .
since i am new to this type of concepts .Help me
Prabhakar.A
Software Engineer
|
|
|
|
|
Let’s say we have a product table where each row represents product details like product Id, Name, Description , Price etc.
Now customer might be interested to view products across (i.e. columns) and features down (row wise). This basically requires transposing product table’s rows and columns as illustrated below.
The first step is to create the new Data Table and its schema from the rows of the input table. In the following code snippet, source refers to the input table and dest is the new pivoted table.
//Create Destination Table
DataTable dest = new DataTable("Pivot" );
// from each source table row (1st column)
// create a destination column
foreach( DataRow r in source.Rows )
dest.Columns.Add( r[0].ToString() );
// assign each row the Product name Now that we have the appropriate columns defined
in the schema of the destination table, the next step is to create a DataRow for each feature defined in the columns of the source table, excluding the first column representing the Product name.
//Create columns in destination table for each row in source table.
for( int i = 0; i < source.Columns.Count - 1; i++ )
dest.Rows.Add( dest.NewRow() );
The final step is the actual transform of the columns from the source rows into the destination table. Since each table now represents a two dimensional array of its rows and columns, a very simple transform of all columns and rows could be performed by the following nested for loop.
//Transpose rows and columns
for( int r = 0; r < dest.Rows.Count; r++ )
for( int c = 0; c < source.Columns.Count; c++ )
dest.Rows[r][c] = source.Rows[c][r];
Ravindra Sadaphule
MCSD.NET
|
|
|
|
|
Thanx,
But I am asking Microsoft Office Pivot Table 9.0 component in asp.net
Prabhakar.A
Software Engineer
|
|
|
|
|
I have two classes named Table and Column.
In Table object, I have many instances of Column object. And in each Column object, I have a property named Table which will return the Table object that this Column object belongs to.
Let see this:
public class Table
{
private name;
private Column[] columns;
public string Name
{
set{name = value;}
get{return name;}
}
public Column[] Columns
{
set{columns = value;}
get{return columns;}
}
}
public class Column
{
private name;
private Table tableParent;
public string Name
{
set{name = value;}
get{return name;}
}
public Table TableParent
{
set{...}
get{...}
}
}
public class Use
{
Table t = new Table();
t.Name = "table";
Column[] cs = new Column[2];
cs[0].Name = "column1";
cs[0].TableParent = t;
cs[1].Name = "column2";
cs[1].TableParent = t;
//Change property of t object
t.Name = "tableChanged";
// I have to change TableParent of each column object manually
for(int i=0;i
|
|
|
|
|
Huh? Your Column objects are holding a reference to a Table object each, so changing the properties of the table means changing the property of the object your references are pointing to.
No need to change the TableParent, it hasn't changed!
mav
|
|
|
|
|
Dear,
While I am using smart device application using C# under “Mobile Application Development Toolkit\Labs\Introduction_to_Windows_Mobile C#”
This is downloaded from http://msdn.microsoft.com/mobility/thekit/
I am getting the following error in Pocket PC 2002 emulator as(if u run without debugging).
PdaClient.exe –Unhan
A managed WebException occurred at SoapHttpClientProtocol::doInvoke+0x23f
Unable to connect to the remote server
SoapHttpClientProtocol::doInvoke+0x23f
SoapHttpClientProtocol::Invoke+0x9
PdaWs::GetAuthors+0x11
Authors::AuthorsLoad+0xd
Form::OnLoad+0x15
Form::_SetVisibleNotufy+0x1d
Control::set_Visible+0x1f
Application::Run+0x7
Authors::Main+0xa
OK to terminate
Please let me know the details of the error and how to correct this one.
Thanks & Regards,
Sivaji Raju.
|
|
|
|
|