|
I want to know how to use DataGridColumnStyle to set the width of my datagrid. I know how to use PreferredColumnWidth to set the width of the oveall colunm, but it is not what I want. I want to set individual column.
Here is my program
I also want to know if there is a good documentation for the .net classes. While I was working in the DataGridClass. My class is defined as dataGrid1, from dataGrid1, there is not way to know that DataGridColumnStyle exists. I want to know is there is a good book or documentation tha point out intaction between associated classes like for instance DataGrid and DataGridColumnStyle.
<br />
private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
double[] dData1 = new double[100];<br />
double[] dData2 = new double[100];<br />
<br />
DataTable dt = new DataTable();<br />
DataRow dr;<br />
<br />
dt.Columns.Add(new DataColumn("Index", typeof(int)));<br />
dt.Columns.Add(new DataColumn("Sinve Values", typeof(float)));<br />
dt.Columns.Add(new DataColumn("Cosine Values", typeof(float)));<br />
<br />
dataGrid1.PreferredColumnWidth = 100;
<br />
for(int i=0;i<100;i++)<br />
{<br />
dData1[i] = Math.Sin(0.1*i);<br />
dData2[i] = Math.Cos(0.2*i);<br />
dr = dt.NewRow();<br />
dt.Rows.Add(dr);<br />
dr[0] = i;;<br />
dr[1] = dData1[i];<br />
dr[2] = dData2[i]; <br />
} <br />
dataGrid1.DataSource = new DataView(dt); <br />
waveformPlot1.PlotY(dData1);<br />
waveformPlot2.PlotY(dData2);<br />
}<br />
|
|
|
|
|
If you want to know if there's good documentation, then read it and determine whether you think it's good.
You can set the width of a specific column using a DataGridColumnStyle that you add to a DataGridTableStyle for a specific DataTable (or type, if reflecting against something other than a DataSet or DataTable ), which you add to DataGrid.TableStyles .
You should read the documentation, which also presents articles. The DataGridColumnStyle does exactly what you're asking and is specific to the column it represents in a DataGrid .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
After adding all these extra codes, it still doesn't work. It shouldn't take all too much effort jsut to increse or decrease the length of a column in a grid.
In terms of the documentation, I think it would have been bette to show interaction from one class to another.
<br />
private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
double[] dData1 = new double[100];<br />
double[] dData2 = new double[100];<br />
<br />
DataTable dt = new DataTable();<br />
DataRow dr;<br />
DataGridTableStyle ts1 = new DataGridTableStyle();<br />
DataGridColumnStyle boolCol = new DataGridBoolColumn();<br />
<br />
dt.Columns.Add(new DataColumn("Index", typeof(int)));<br />
dt.Columns.Add(new DataColumn("Sinve Values", typeof(float)));<br />
dt.Columns.Add(new DataColumn("Cosine Values", typeof(float)));<br />
<br />
ts1.MappingName = "Index";<br />
boolCol.MappingName = "Index";<br />
boolCol.Width = 20;<br />
ts1.GridColumnStyles.Add(boolCol); <br />
dataGrid1.TableStyles.Add(ts1);<br />
<br />
for(int i=0;i<100;i++)<br />
{<br />
dData1[i] = Math.Sin(0.1*i);<br />
dData2[i] = Math.Cos(0.2*i);<br />
dr = dt.NewRow();<br />
dt.Rows.Add(dr);<br />
dr[0] = i;;<br />
dr[1] = dData1[i];<br />
dr[2] = dData2[i]; <br />
} <br />
dataGrid1.DataSource = new DataView(dt); <br />
waveformPlot1.PlotY(dData1);<br />
waveformPlot2.PlotY(dData2);<br />
}<br />
|
|
|
|
|
It's not difficult, but your problem is that you need to name your DataTable . The DataGrid associates a particular DataGridTableStyle with a DataGrid by matching the DataTable.TableName (you can pass this to the constructor) with one of the DataGridTableStyle 's MappingName that was added to the DataGrid.TableStyles property. Your modified code below works fine:
double[] dData1 = new double[100];
double[] dData2 = new double[100];
DataTable dt = new DataTable("Test");
DataRow dr;
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = dt.TableName;
DataGridColumnStyle boolCol = new DataGridBoolColumn();
dt.Columns.Add("Index", typeof(int));
dt.Columns.Add("Sinve Values", typeof(float));
dt.Columns.Add("Cosine Values", typeof(float));
boolCol.MappingName = "Index";
boolCol.Width = 20;
ts1.GridColumnStyles.Add(boolCol);
dataGrid1.TableStyles.Add(ts1);
for (int i=0; i<100; i++)
{
dData1[i] = Math.Sin(0.1*i);
dData2[i] = Math.Cos(0.2*i);
dr = dt.NewRow();
dt.Rows.Add(dr);
dr[0] = i;
dr[1] = dData1[i];
dr[2] = dData2[i];
}
dataGrid1.DataSource = dt; You did, however, forget to add column styles for your other columns. When you use table styles with defined columns (even just 1), no columns are auto-generated.
Besides, using a DataTable here is unnecessary. A simple array of some struct like so would work:
public struct Data
{
public int Index;
public double Sinve;
public double Cosine;
} In this case, you set DataGridTableStyle.MappingName to "Data". This is documented in the DataGridTableStyle.MappingName property documentation.
Also, why are you binding a DataGridBooleanColumn to an int DataColumn ? That's going to set it to either 0 or 1 and will start (for all but the first row) in an indeterminate state.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am trying to create a generalized control that functions similarly to the ASP Image Button control but with the added feature of being able to programmatically superimpose text over the image.
There are many times when a GUI developer would like to create an image and programmatically place specific text on that image. For example: A restaurant application that graphically shows a restaurant table layout as an icon (see below). It would be nice to be able to write text over the table icon that is meaningful to the user of the application rather than place text outside the image area. When the user clicks on the table, an event handler would process whatever the application requires.
Table ID = A7
Guest Count = 3 people
Server ID = 22
It would be far better from a GUI view point to create a larger Image and place the actual text directly in the image:
Likely this Server control needs to look exactly like the ImageButton with an added attribute perhaps called ImageTextLine with properties:
ImageTextLine.Text
ImageTextLine.Alignment (Top, Center, Left, Right)
A single text line could suffice with string concatenation handling the actual display.
This must be a generalized sever control that will take any image and allow text to be placed over the top of the image in various alignment positions.
The closest I can come to finding anything remotely resembling the above scenario is creating a text-image which uses GDI+ to create a rectangle or circle (ellipse) as a drawing shape. I don’t want a rectangle or circle, I want an image of my choosing.
|
|
|
|
|
So what's your question?
If you want to know how to do this, there's many articles here on CodeProject and other sites about drawing images in ASP.NET (BTW, next time post ASP.NET-related questions in the ASP.NET forum) either to the response stream or to a persistent file (can be dangerous).
Specifically, read the documentation for the Graphics.MeasureString and Graphics.DrawString methods, which also provide examples.
You could even load-up a template image using either the Bitmap constructor or either Image.FromFile or Image.FromStream , call Graphics.FromImage , and draw your text (always remember to call Graphics.Dispose when finished).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I have been writing a C# app with a three tier (Database, business and user level) approach. I would like to do some testing across a network but have no idea on how to expose the business layer on the sever machine so other computers can then use this component across the network.
Can anyone point to an article that will direct me on how to do this?
The machines are XP/2000 machines.
Thanks in advance.
Stephen
|
|
|
|
|
Why do you want to expose it over the network, unless you intend to do that anyhow ?
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
What do you want to test of the business layer? The interaction interfacing with the user level or the database level?
How do you currently get these two levels to interact with each other?
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
On the server I want to run both the data and business tier and run only the user interface on each work station.
I need to test this to make sure that this will work fine first before installing the app and so i would like to test it on my home network.
Can anyone help?
Thanks
|
|
|
|
|
You can't do this automatically.
If remote access was your requirement, you should be using .NET remoting. However this was a thing to consider in the design phase. Now that you already done some amount of coding, I am afraid you have to re-code to incorporate .NET remoting in your code.
Refer MSDN and Code Project regarding tutorials on this topic.
Salil Khedkar [^]
|
|
|
|
|
|
Thanks Carl. That is great.
Regards
Stephen
|
|
|
|
|
Hello,
I have a data grid that contains 5 columns. I want the columns to be displayed a different lengths at run-time. But l have tired using the properties but cannot find anything that will adjust the columns to the width that l require. They seem to stay at their defaulf widths.
Many thanks in advance,
Steve
|
|
|
|
|
The best solution is to just use defined table styles instead of auto-generated styles. Read about the DataGrid.TableStyles propert and related classes at http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsDataGridClassTableStylesTopic.asp[^] in the online .NET Framework SDK (or simply type "DataGrid.TableStyles" in your local installation or in VS.NET's Index).
This allows you to specifically add one or more styles for one or more table names (or property names if binding to an IList or IListSource implementation other than a DataTable or DataSet ) that explicitly defines column styles for named DataColumn s (or inner property names).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello,
I have adjusted some properties in the tablestyle and columnstyle design properties, but l still can't get it to work. This what l have done:
In my database l have a table called Book
I have 3 collumns called RefNumber, Title, and Remarks
my datagrid code to bind to the datatable is:
grdStudents.Source = dtStudents();
grdReflesh();
Now I design the datagrid columns shape.
In the datagrid properties i have a property called : tablestyles, inside it is a designer . I add a new tablestyle and make it's mapping = "Book"
so this table properties will be applied on the table called "Book" which is the name of the table
Inside this table styles there is a gridcolumnstyles property, inside it there is a designer, I add the columns I want inside it and set their properties (height,width etc....) and for each column set it's mapping name to the column names. I l have 3 columns styles mapped to RefNumber, Title, and Remarks.
After doing all this l still can't get it to work. I have used the datatable, but will this work with only using a dataset. I am not sure.
Thanks in advance for any help,
Steve
|
|
|
|
|
The column and table styles should be assigned before you set the DataGrid.DataSource .
If you actually read the documentation for DataGrid.DataSource , you'll see that any IList or IListSource will do. You can assign either a DataSet or DataTable , but I recommend assigning the DataSet to DataGrid.DataSource and the name of the table to DataGrid.DataMember . Finally, make sure that for your DataGridTableStyle you set the MappingName to the DataTable name (if you follow my advice above, this would be the same as the DataGrid.DataMember name, but still works if you assign the DataTable to the DataGrid.DataSource instead). The documentation for the DataGridTableStyle.MappingName describes this, as well as what to assign as the MappingName if you're reflecting against IList or IListSource implementations besides the DataSet and DataTable classes.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi all,
I have a combo box and a text box on a form. cmb1 and txt1 for arguments sake. The tab order means that when tab is pressed focus moves from cmb1 to txt1. What i want to do is allow for the user to press the enter key and simulate the tab key being pressed, i.e. focus moves to the next control on the tab order.
Any ideas?
Cheers
Kev
|
|
|
|
|
You could check for the Enter key in the combo's KeyPress event, then transfer focus to the next in the tab order.
private void comboBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if ( e.KeyChar == (char)13 )
{
this.GetNextControl(this.ActiveControl, true).Focus();
}
}
Roger Stewart
"I Owe, I Owe, it's off to work I go..."
|
|
|
|
|
You should actually use KeyCode.Enter . While this will probably always be character code 13, without optimization (based on the compiler) (char)13 may require additional instructions for the cast while using KeyCode.Enter will always compile to 13 without a cast.
Besides, it's best to avoid "magic numbers" and makes for more elegant code.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I took this (the char 13) straight out of MSDN Library for the KeyPressEventArgs.KeyChar Property[^]. You might want to pass your suggestion on to MSDN Lib guys
Roger Stewart
"I Owe, I Owe, it's off to work I go..."
|
|
|
|
|
Thanks Roger,
Works great.
Kev
|
|
|
|
|
I'm trying to create rotatable widgets. I tried to rotate the graphic surface but that is not enough, I have to rotate the clip rectangle of the components too, in order to create the right paint area and to receive the mouse events in the correct way. Alternatively, I created my own components from scratch, and implemented everything, but I would rather use .Net components and just extend them. But I'm not sure if that is possible. Is there anybody who knows if it is possible and, if yes, how can I?
I am using C# with .Net 1.1.4322.
|
|
|
|
|
The Graphics class defines several helpful transformation methods like Graphics.RotateTransform for this specific purpose. If you apply this as the world transform, than even your clipping region (whether you fill a Region yourself or use a GraphicsPath (most handy, BTW!) is rotated.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thank you. But, I'm sorry, I don`t understand what you mean for "apply this as the world transform". If I extend a Button Class and I call RotateTransform to its Graphic obj it will only change the graphic surface, but not the . Can you give me a little example of your solution?
|
|
|
|