|
Hi !
I'm using Visual Studio 2005 Professional Edition and C#.
I have a simple question:
I want to add to my form, which is a scrollable control, a menustrip and
statusstrip.
The problem is that the menustrip is not fixed at top if i scroll down.
A similar problem exists also for the statusstrip. If i open the program it
is only visible if i scroll down.
The program thinks that the menustrip and the statusstrip are in the Client
region, to which i want to draw something.
So, how can I fix them, so that they are not get lost if i scroll the main
form up or down ?
--
Schwammkopf
PS: The AutoScrollMinSize is set to (ClientSize.Width + 50,
ClientSize.Height + 50). Of course, on each OnPaint i update it.
|
|
|
|
|
In your form you should put a ToolStripContainer, with your MenuStrip at the top and your StatusStrip at the bottom. Then you add your scrollable control in the middle/center of this ToolStripContainer.
Internet - the worlds biggest dictionary
|
|
|
|
|
well, the problem is that my main form is a scrollable control. and i can put it in the container.
besides, how is possible to let the container take the size of the main form if someone resize the mainform ?
|
|
|
|
|
I suppose you have to change it then? Instead of creating a scrollable form, you create a scrollable UserControl, which you can put in any container.
Internet - the worlds biggest dictionary
|
|
|
|
|
Hi All,I'm working on a control derived from UserControl class.
By Default UserControl Class have 6 glyphs for Resizing around the canvas rectangle.
X-----X-----X
| |
X X
| |
X-----X-----X
I marked them with an "X" for an immediate reference.
I need to override them for changing the color of the extreme four:
X-----------X
| |
| |
| |
X-----------X
when a selection rectangle include one of them,two,three or all four,It should become red.
(For sure,if someone knows how override color,will be easy to override the shape(a GraphicPath instead of little rectangles maybe....))
But I cannot Find litterally ANYONE who knows how I can access to adorners and behaviorservice
properties of the Adorners/Glyphs of UserControl Class in .NET 2.0.
Please,it's a week I dig around,Help me!
Thanks So Much!
Frank Drebin
|
|
|
|
|
I have XML file embedded in my C# Winforms application.
I need to add data to <pre><ConnectString></ConnectString></pre>
element so it looks like
<pre><ConnectString>database=mydb;server=localhost;user=myuser</ConnectString></pre>
and return it as string. I created the following method.
Which XmlDocument function I should use to add data to ConnectString node ?
<pre>string GetDefaultReport(string connectionString) {
Stream stream = GetType().Assembly.GetManifestResourceStream
("mynamespace.DefaultReport.xml");
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(stream);
// todo: replace <ConnectString></ConnectString>
// with <ConnectString> connectionString value </ConnectString>
return xmlDocument.InnerXml;
}<pre>
xml file looks as follows:
<pre><?xml version='1.0' encoding='utf-8'?>
<Report xmlns='http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition'
xmlns:rd='http://schemas.microsoft.com/SQLServer/reporting/reportdesigner'>
<DataElementStyle>ElementNormal</DataElementStyle>
<RightMargin>0.25in</RightMargin>
<Body>
<ReportItems>
<List Name='list1'>
<DataInstanceName>Row</DataInstanceName>
<NoRows>Selliseid andmeid pole</NoRows>
<Style />
<DataSetName>Data</DataSetName>
<ReportItems>
<Textbox Name='Algus'>
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>1</ZIndex>
<CanGrow>false</CanGrow>
<Value>=Fields!akuupaev</Value>
<Width>1in</Width>
<Height>14pt</Height>
</Textbox>
<Textbox Name='Lõpp'>
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<Left>1.5in</Left>
<Width>1.5in</Width>
<Height>14pt</Height>
<CanGrow>false</CanGrow>
<Value>=Fields!lkuupaev</Value>
</Textbox>
</ReportItems>
</List>
</ReportItems>
<Style />
<Height>0.25in</Height>
<ColumnSpacing>0.25in</ColumnSpacing>
<Columns>1</Columns>
</Body>
<TopMargin>0.5in</TopMargin><DataSources>
<DataSource Name='DS1'>
<ConnectionProperties>
<DataProvider>PostgreSQL</DataProvider>
<ConnectString></ConnectString>
</ConnectionProperties>
</DataSource>
</DataSources>
<DataSets>
<DataSet Name='Data'>
<Query> <DataSourceName>DS1</DataSourceName>
<CommandText>SELECT akuupaev,lkuupaev FROM {1}.kontekst</CommandText>
</Query>
<Fields>
<Field Name='akuupaev'>
<DataField>akuupaev</DataField>
<rd:TypeName>System.DateTime</rd:TypeName>
</Field>
<Field Name='lkuupaev'>
<DataField>lkuupaev</DataField>
<rd:TypeName>System.DateTime</rd:TypeName>
</Field>
</Fields>
</DataSet>
</DataSets>
<LeftMargin>0.25in</LeftMargin>
<BottomMargin>0.5in</BottomMargin>
<Width>2.5in</Width>
<PageHeader>
<Height>22.8pt</Height>
<ReportItems>
<Textbox Name='lehepealkiri'>
<Height>12pt</Height>
<Width>5in</Width>
<Value>{2}</Value>
<Left>30.9pt</Left>
<Top>5.8pt</Top>
</Textbox>
</ReportItems>
<PrintOnFirstPage >true</PrintOnFirstPage>
<PrintOnLastPage >true</PrintOnLastPage>
</PageHeader>
<PageFooter>
<Height>0pt</Height>
</PageFooter>
</Report>
</pre>
-- modified at 18:56 Monday 12th February, 2007
Andrus
|
|
|
|
|
set the path to the node which you want to update, later then you could give node.innerhtml=node.innnerhtml +"....."
Hope this works!!
Gautham
|
|
|
|
|
Thank you.
I'm new to C# XML. how to set path to node ?
I think I need simething like
Node node=xmlDocument.SelectNode(/DataSource/ConnectionProperties/ConnectString" );
node.InnerHTML = "database=mydb;host=localhost;user=myuser");
but this causes compile error.
Why ?
Andrus
|
|
|
|
|
AndrusM wrote: but this causes compile error.
Why ?
If you get errors or exceptions, it is always a good idea to tell us exactly what they are. Simply saying "it does not work" or "it causes error/exceptions" makes it harder to help.
Anyway, in the given case it is quite obvious:
1. The XmlDocument class provides no SelectNode method. There are only the SelectNodes and SelectSingleNode methods. You have to use the latter.
2. The starting quote for the XPath expression is missing.
3. There is no type called Node . It's XmlNode .
4. The XmlNode class provides no InnerHTML property. There are a InnerText and InnerXml property. You could use both.
After applying the above changes your code should compile, but it won't work because your XPath expression will not select the element you want. The reason is that all elements in your XML file are qualified with the 'http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition' namespace through the xmlns declaration on the root element. Your XPath expression will match only unqualified elements. To resolve this issue use the overload of the XmlDocument.SelectSingleNode method that takes an XmlNamespaceManager object. The MSDN topic of the method contains an example that shows you how to do this.
Finally, a small hint (not meant to offend you). You should definitely learn to work with the documentation. It extensively documents the classes of the .NET FRamework class library and contains many examples on how to use them. For example, it would have been plain visible why your code cannot compile by taking a look at the documentation of the classes in question (a method or property that is not listed and described there, is very unlikely to exist and therefore its use will cause compile errors). So, first try to solve your problem by looking at the documentation. If you cannot come up with a solution, try the search engine of your choice. If still no solution, come here and feel free to ask. This process seems time-consuming at the beginning, but it helps alot improving your programming skills and with some practise it get faster and faster.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thank you very much for help.
I created the following procedure but node value is null.
Why SelectSingleNode() does not return value ?
string GetDefaultReport() {
Stream stream = GetType().Assembly.GetManifestResourceStream
("mynamespace.DefaultReport.xml");
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(stream);
XmlNode node = xmlDocument.SelectSingleNode("/DataSource/ConnectionProperties/ConnectString",
new XmlNamespaceManager(xmlDocument.NameTable));
node.InnerText = "host=localhost;user=admin;database=mydb";
return xmlDocument.InnerXml;
}<pre>
I havent found the XmlNamespaceManager() sample in MSDN.
I have C# Express 2005. Its documentation viewer is not usable. After I press F1 key, it takes 1-2 minutes for documentation viewer to open. It takes also a lot of time to search for every topics.
Documentation viewer is incomplete. In many cases is show error that topics is not available offline. Since I don't have permanent internet connection in many times, it is not possible to get help.
I have dial-up connection and for this reason I have turned images off in IE.
Unfortunately this causes documentation viewer not to dispaly images and corresponding help texts. I must press two (!) times to collapse/expand button to get text readable.
Sime time ago Microsoft offers to download MSDN from their website. However, this download is now closed.
Where to download complete .NET + C# documentation for fast offline view ? CHM format is sufficient for me.
<div class="ForumSig">Andrus</div>
|
|
|
|
|
Ok, first of all here is the link to the MSDN topic with the example: XmlNode.SelectSingleNode Method (String, XmlNamespaceManager)[^]
To make it easier for you here is the example given there:
<bookstore xmlns="http://www.lucernepublishing.com">
<book>
<title>Pride And Prejudice</title>
</book>
</bookstore>
The following C# code selects the first book node:
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("ab", "http://www.lucernepublishing.com");
XmlNode book = doc.SelectSingleNode("//ab:book", nsmgr);
Your procedure does not work because your XPath expression is still looking for unqualified elements. Xpath does not offer an default namespace feature as XML files, at least I do not know of such a feature. Therefore, you have to prefix all element names with a specific prefix that maps to the right namespace URI (this mapping is what the namespace manager is for). Since your XML file makes use of a default namespace, it's quite likely that passing documents name table is not sufficient and you are required to add a prefix-namespaceUri-mapping as shown in the example.
[edit]
I was right :-> MSDN states:
"If the XPath expression does not include a prefix, it is assumed that the namespace URI is the empty namespace. If your XML includes a default namespace, you must still add a prefix and namespace URI to the XmlNamespaceManager; otherwise, you will not get a node selected. For more information, see Select Nodes Using XPath Navigation[^]."
[/edit]
AndrusM wrote: Where to download complete .NET + C# documentation for fast offline view ?
Some days ago, someone posted in this forum that you cannot download the documentation for free. You can get it on DVD, but for this you need a MSDN subscription for some hundred dollars if i recall the posting right.
AndrusM wrote: After I press F1 key, it takes 1-2 minutes for documentation viewer to open
Maybe, you can speed this up. Open the options of Visual Studio (available under menu item "extras"). Then go to "environment>help>online". At the top edge, you can define where Visual Studio looks for the requested help first. By default, it first tries to lookup online, what may be the reason for the long delay.
-- modified at 16:28 Tuesday 13th February, 2007
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thank you very much for help.
I tried
string GetDefaultReport() {
Stream stream = GetType().Assembly.GetManifestResourceStream
("mynamespace.DefaultReport.xml");
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(stream);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable);
nsmgr.AddNamespace("def", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");
XmlNode node = xmlDocument.SelectSingleNode("/def:DataSource/def:ConnectionProperties/def:ConnectString", nsmgr );
....
but SelectSingleNode() still returns null.
What I'm doing wrong ?
In Help / Online I have radio button in choice "Try local only, not online".
In first attepmpt in C# Express 2005 when I highlight some item and press F1, it takes 1-2 minutes to open help window. hdd led is on and cpu usage is 10 .. 20% so I think that this time is wasted for reading data from hard disk.
I have Acer Travelmate 273LC notebook with 1.7 GHz Mobile Intel Pentium, 256 MB RAM, 20 GB Ultra ATA/100 HDD, no other applications opened.
Andrus
|
|
|
|
|
The default namespace URI is "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" not "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner".
Furthermore, according to the XML file shown in your original post the XPath expression should be "/def:DataSources/def:DataSource/def:ConnectionProperties/def:ConnectString".
AndrusM wrote: In first attepmpt in C# Express 2005 when I highlight some item and press F1, it takes 1-2 minutes to open help window. hdd led is on and cpu usage is 10 .. 20% so I think that this time is wasted for reading data from hard disk.
Mmh, I honestly do not know how to resolve this. Could be your working memory is to small and windows needs to swap something into virtual memory (according to MSDN your system does not meet the system requirements of VS 2005). Maybe your hard drive is defragmented and therefore searching needs some time. Maybe it's a mix of both. Hard to tell.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thank you. I tried it but
node.InnerText = "test";
still causes null reference exception.
Complete test case is in bottom of this message.
I think I must buy new notebook for VS development. Maybe this solves the issue. I'll try to find 7400 RPM disk and 1 GB RAM. Currently I have 5400 RPM disk. I have read somewhere that MS and Intel have made a contract. According to this MS releases new software every year which forces people to by new hardware.
using System.Xml;
class Program {
const string s = @"<?xml version='1.0' encoding='utf-8'?>
<Report xmlns='http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition'
xmlns:rd='http://schemas.microsoft.com/SQLServer/reporting/reportdesigner'>
<DataElementStyle>ElementNormal</DataElementStyle>
<RightMargin>0.25in</RightMargin>
<Body>
<ReportItems>
<List Name='list1'>
<DataInstanceName>Row</DataInstanceName>
<NoRows>Selliseid andmeid pole</NoRows>
<Style />
<DataSetName>Data</DataSetName>
<ReportItems>
<Textbox Name='Phone'>
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>1</ZIndex>
<CanGrow>false</CanGrow>
<Value>=Fields!Kood.Value</Value>
<Left>1.5in</Left>
<Width>1in</Width>
<Height>14pt</Height>
</Textbox>
<Textbox Name='ContactName'>
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<Width>1.5in</Width>
<Height>14pt</Height>
<CanGrow>false</CanGrow>
<Value>=Fields!Nimetus.Value</Value>
</Textbox>
</ReportItems>
</List>
</ReportItems>
<Style />
<Height>0.25in</Height>
<ColumnSpacing>0.25in</ColumnSpacing>
<Columns>1</Columns>
</Body>
<TopMargin>0.5in</TopMargin><DataSources>
<DataSource Name='DS1'>
<ConnectionProperties>
<DataProvider>PostgreSQL</DataProvider>
<ConnectString></ConnectString>
</ConnectionProperties>
</DataSource>
</DataSources>
<DataSets>
<DataSet Name='Data'>
<Query> <DataSourceName>DS1</DataSourceName>
<CommandText>SELECT * FROM nomenkla</CommandText>
</Query>
<Fields>
<Field Name='Nimetus'>
<DataField>nimetus</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name='Kood'>
<DataField>kood</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
</Fields>
</DataSet>
</DataSets>
<LeftMargin>0.25in</LeftMargin>
<BottomMargin>0.5in</BottomMargin>
<Width>2.5in</Width>
<PageHeader>
<Height>0pt</Height>
</PageHeader>
<PageFooter>
<Height>0pt</Height>
</PageFooter>
</Report>";
static void Main() {
GetDefaultReport(s);
}
static string GetDefaultReport(string s) {
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.InnerXml = s;
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable);
nsmgr.AddNamespace("def", "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
XmlNode node = xmlDocument.SelectSingleNode("/def:DataSources/def:DataSource/def:ConnectionProperties/def:ConnectString", nsmgr);
node.InnerText = "test";
return xmlDocument.InnerXml;
}
}
Andrus
|
|
|
|
|
AndrusM wrote: XmlDocument xmlDocument = new XmlDocument();
xmlDocument.InnerXml = s;
What's this s? If it is a string representation of a XML file that you want to assign to the document, use the XmlDocument.LoadXml method instead.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thank you.
I changed the line to
xmlDocument.LoadXml(s);
but node value is still null.
Andrus
|
|
|
|
|
Ok, since the code should work as it is, I would first check whether the XmlDocument instance really contains what you expect it to. Easiest way, would be writing the document to some test file by using the XmlDocument.Save method.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
I added a line
xmlDocument.Save(@"c:\test.xml");
text.xml seems to be OK.
So is this .NET bug ?
text.xml contains:
’╗┐<?xml version="1.0" encoding="utf-8"?>
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
<DataElementStyle>ElementNormal</DataElementStyle>
<RightMargin>0.25in</RightMargin>
<Body>
<ReportItems>
<List Name="list1">
<DataInstanceName>Row</DataInstanceName>
<NoRows>Selliseid andmeid pole</NoRows>
<Style />
<DataSetName>Data</DataSetName>
<ReportItems>
<Textbox Name="Phone">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>1</ZIndex>
<CanGrow>false</CanGrow>
<Value>=Fields!Kood.Value</Value>
<Left>1.5in</Left>
<Width>1in</Width>
<Height>14pt</Height>
</Textbox>
<Textbox Name="ContactName">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<Width>1.5in</Width>
<Height>14pt</Height>
<CanGrow>false</CanGrow>
<Value>=Fields!Nimetus.Value</Value>
</Textbox>
</ReportItems>
</List>
</ReportItems>
<Style />
<Height>0.25in</Height>
<ColumnSpacing>0.25in</ColumnSpacing>
<Columns>1</Columns>
</Body>
<TopMargin>0.5in</TopMargin>
<DataSources>
<DataSource Name="DS1">
<ConnectionProperties>
<DataProvider>PostgreSQL</DataProvider>
<ConnectString>
</ConnectString>
</ConnectionProperties>
</DataSource>
</DataSources>
<DataSets>
<DataSet Name="Data">
<Query>
<DataSourceName>DS1</DataSourceName>
<CommandText>SELECT * FROM nomenkla</CommandText>
</Query>
<Fields>
<Field Name="Nimetus">
<DataField>nimetus</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="Kood">
<DataField>kood</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
</Fields>
</DataSet>
</DataSets>
<LeftMargin>0.25in</LeftMargin>
<BottomMargin>0.5in</BottomMargin>
<Width>2.5in</Width>
<PageHeader>
<Height>0pt</Height>
</PageHeader>
<PageFooter>
<Height>0pt</Height>
</PageFooter>
</Report>
Andrus
|
|
|
|
|
No, there is no bug. Seems the XPath expression is still not right. Try "/def:Report/def:DataSources/def:DataSource/def:ConnectionProperties/def:ConnectString" or "//def:DataSources/def:DataSource/def:ConnectionProperties/def:ConnectString"..
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thank you very much. It works. Excellent.
Assigning string to InnerXML property works also.
I have no idea why you ordered to use LoadXML()
Andrus
|
|
|
|
|
I need to convert datareader to stongly typed entity list.
The following procedure returns error.
How to fix this ?
List<xEntity> CreateEntityList<xEntity>(IDataReader dataReader) {
List<xEntity> list = new List<xEntity>();
while (dataReader.Read()) {
object[] o;
dataReader.GetValues(o);
list.Add(o);
}
dataReader.Close();
return list;
}
Andrus
|
|
|
|
|
I had some reports that were local and pointed at a DataSet using an xsd file as the basis for creating the report, then using a stored procedure to fill the ds, assignig it to the report as the report source
oRpt.Load(_templatePath + _templateName);
oRpt.SetDataSource(ds);
now I have set up a webservice to provide the reports and I can assign an actual table to the report but can't seem to use one of the existing reports - as report keeps asking me to log into the MS SQL database - and since I am using the system authentication has me stumped.
Is there a way I can change the datasource of a webservice report before sending it across - or after?
Thanks
David Bambrick
|
|
|
|
|
What is best method to do this on Order Details data grid, when user select ProductID ProductPrice is automatically filled with value from Product table... and is on save written to Order details (so if price changed in Product table it will not be automatically updated in order details table (only when user select new product)?
I already have idea, tried to do new table adapter that have parameter query that do just that, and have event celled edit call fill on new table adapter... only remaining problem is how to copy new value to existing tableadapter.
I tried some work around things... but none is very professional so I'm looking for some elegant solution.
So how to copy value from that table adapter to data grid cell if possible (I only managed to drag and drop new table adapter and create text box on form, so I copy value of text box to grid, not something I would like to do)?
|
|
|
|
|
OK this can give you some idea...
private void order_DetailsDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)<br />
{<br />
if (order_DetailsDataGridView.Columns[e.ColumnIndex].DataPropertyName == "ProductID")<br />
{this.getProductCurrentPriceTableAdapter.Fill<br />
(this.northWndDataSet.GetProductCurrentPrice, (int)order_DetailsDataGridView[e.ColumnIndex, e.RowIndex].Value);<br />
order_DetailsDataGridView[e.ColumnIndex + 1, e.RowIndex].Value = decimal.Parse(unitPriceTextBox.Text); <br />
}<br />
}
so instead last line I want something better, any idea?
|
|
|
|
|