|
that will do the whole grid i only want a column?
|
|
|
|
|
Then explicitly define a DataGridTableStyle with DataGridColumnStyle derivatives matching up with your columns you want to display. For any columns you want to disable editing, set DataGridColumnStyle.ReadOnly to true . For more about tables styles, see the documentation for the DataGridTableStyle[^] class in the .NET Framework SDK. It also includes sample code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
will this work after binding my grid to the table that i am create from the database ie DataTable tbl = LoadData();
MyDatagrid.DataSource = tbl;
|
|
|
|
|
Yes, and you don't need to re-initialize it. You can even add multiple table styles to handle multiple data sources. Again, read the documentation I provided a link for.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
on the case let you know how i get on many thanks
|
|
|
|
|
I cant see where i am going wrong as my loop shows the readonly to be false for every column even though i am setting them to true in my routine and when i loop through the columnsstyle collection i get false for every one???
private void LoadInvoice(DataGrid invoiceJob,ComboBox phaseName)
{
job = new Job();
DataTable list = job.LoadPhasePayers(Convert.ToInt32(phaseName.SelectedValue.ToString()));
invoiceJob.DataSource = list;
AddCustomDatagridStyle(invoiceJob);
foreach(DataGridTableStyle ts in dtgCInvoice.TableStyles)
{
Debug.WriteLine(ts.ReadOnly);
}
}
private void AddCustomDatagridStyle(DataGrid myGrid)
{
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "PhasePayers";
DataGridColumnStyle textCol = new DataGridTextBoxColumn();
textCol.MappingName = "Payer";
textCol.HeaderText = "Payer";
textCol.Width = 250;
textCol.ReadOnly = true;
ts1.GridColumnStyles.Add(textCol);
myGrid.ReadOnly = true;
myGrid.TableStyles.Add(ts1);
DataGridColumnStyle textCol2 = new DataGridTextBoxColumn();
textCol.MappingName = "Net";
textCol.HeaderText = "Net";
textCol.Width = 250;
textCol.ReadOnly = true;
ts1.GridColumnStyles.Add(textCol2);
myGrid.TableStyles.Add(ts1);
DataGridColumnStyle textCol3 = new DataGridTextBoxColumn();
textCol.MappingName = "VAT";
textCol.HeaderText = "VAT";
textCol.Width = 250;
textCol.ReadOnly = true;
ts1.GridColumnStyles.Add(textCol3);
myGrid.TableStyles.Add(ts1);
DataGridColumnStyle textCol4 = new DataGridTextBoxColumn();
textCol.MappingName = "Gross";
textCol.HeaderText = "Gross";
textCol.Width = 250;
textCol.ReadOnly = true;
ts1.GridColumnStyles.Add(textCol4);
myGrid.TableStyles.Add(ts1);
}
|
|
|
|
|
As I said before, do not initialize the table and column styles every time you set your DataSource , which you currently are. You only need to do this once. The way you're currently doing it, you add new column and table styles each time you set the data source, leading to increasing memory consumption, performance degradation, and other unforseen problems with having the same table style added multiple times. Also, how is setting every column's ReadOnly property to true different from simply setting DataGrid.ReadOnly to true ?
The actual problem is most likely because you're DataGridTableStyle.MappingName is set to the table name of the DataSource you're using, which is a DataTable . If you were to actually use a DataSet and set that as the DataSource with the table name set in the DataGrid.DataMember property (which should be the same as the table style you want to use, since you can have more than one table style). If you set the DataGrid.DataSource to a DataTable ,. then IIRC the DataGridTableStyle.MappingName should be an empty string or null (either would work - just don't set it to begin with, though).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
many thanks for persevering with me i got it thanks to you, setting the mapping name to null was the big key and i am glad you spotted my method of setting on every load i was getting tired and difflated at that stage. I am using tables rather than the overhead of a dataset being returned everytime, i have got styles to work with dataset but my little brain was struggling to get it to work with a table now i am off and running again looking for my next brickwall to knock down ))))))
|
|
|
|
|
now it is getting bigger when i switch between design view and code view it is very slow any ideas on how to spped it up
|
|
|
|
|
are you placing any background image to your window?
I usually disable it.
|
|
|
|
|
|
Hi,
I'm writing a program that performs CRC check on sfv files, I've got a method creating an array that's used for filling a listview item, the array is
<br />
public struct LineToCheck<br />
{<br />
public string fileName;<br />
public ulong CRC;<br />
public LineToCheck(string filename,ulong CRC,)<br />
{<br />
this.fileName=filename;<br />
this.CRC=CRC;<br />
}<br />
};
I added a button in my form to start sfv check but since the array is created in a method, I had to create a public static LineToCheck array as global variable and to use .ToCopy(global_array) to fill it, but doing so I've to fix a lenght of array, if I were in C, I would have used LineToCheck *array, and I would have dinamicly add elements.... is there a way to do so in C#??? or to trim an array at inside's method array's lenght?
I don't know if I've been clear..... I hope so, thanks
Paolo
|
|
|
|
|
yes there is a way to use a dynamical array: the class
ArrayList (I guess in System.Collections )...it automatically resizes when necessary, and thus it has no fixed length as a "normal" array in C#....but ArrayList stores the assigned values as objects (aka boxing), so you have to cast when you return something from the ArrayList....
for example:
int i = 5;
ArrayList al = new ArrayList();
al.Add(i);
int storedInt = (int) al[0]; //unboxing
|
|
|
|
|
|
Note that boxing and unboxing is only done when casting value types from an object reference. Casting a reference object does not box or unbox, it simple performs a cast.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
anybody knows about that? please give me one basic example how to use API in C#
nam
|
|
|
|
|
Try this article[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event[^].
|
|
|
|
|
thanks Colin Angus Mackay alot
nam
|
|
|
|
|
|
well, it's easy to understand for the beginner, thanks Jay_sh_s alot
nam
|
|
|
|
|
Hi All,
I want to disable text resize of texts of a rich text box when Ctrl + Mouse Wheel scroll is being proformed.
Any idea!! Any clues!! How to fix it.
Please suggest...
Thanks in advance,
Regards,
Jay.
|
|
|
|
|
Extend the RichTextBox class and override WndProc . If you don't want to allow zooming at all, catch the EM_SETZOOM (0x04e1) and don't call base.WndProc . If you don't want the mouse to be able to set the zoom factor, then catch the WM_MOUSEWHEEL (0x020a) and use the static Control.ModiferKeys properties to easily determine if the Ctrl+MouseWheel is in effect. If it is, again, don't call base.WndProc . In all other cases, be sure to call base.WndProc passing a reference to the Message struct otherwise your control will not work at all and may not even be initialized correctly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Heath,
Thanx a lot, I could solve the problem by
1.Extending the RichTextBox class
2. Catching WM_MOUSEWHEEL (0x020a) and
checking whether Control.ModiferKeys is Keys.Control
3. not calling base.WndProc in the above case (mentioned in 2).
Where as I could not get the result by Catching EM_SETZOOM (0x04e1) and not calling base.WndProc.
I am keen to know whether is it possible to solve the problem using EM_SETZOOM ?
Please Comment.
Thanks and Regards,
Jay.
|
|
|
|
|
RichTextBox.ZoomFactor is also between 0.64 and 64.0 because it simply uses the EM_GETZOOM and EM_SETZOOM message which it sends to the underlying window handle, same as practically all the controls in Windows Forms.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Heath,
Thanks for the info. using EM_SETZOOM should give the same result.But it does not work
I tried to catch the EM_SETZOOM using the following code
Did I go wrong somewhere in implementation?. Please comment.
protected override void WndProc(ref System.Windows.Forms.Message m)<br />
{<br />
<br />
if (m.Msg == 0x04e1)
{<br />
return;<br />
<br />
}<br />
else<br />
{<br />
base.WndProc(ref m);<br />
<br />
}<br />
<br />
}
Where as catching WM_MOUSEWHEEL and asserting Control.ModifierKeys == Keys.Control solves the problem.
Thanks and Regards,
Jay.
|
|
|
|