|
1 - you can iterate over all the rows and find which ones are selected
2 - you may be able to do this with a keyboard hook, but why would you do such a user hostile thing ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: user hostile
Now, there is a great expression I'll have to remember.
|
|
|
|
|
Hi,
My program writes this xml file:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<CarInformation />
<DateOfBuilding>9/15/2006</DateOfBuilding>
<TimeOfBuilding>9:48:51 AM</TimeOfBuilding>
<CarInformation />
</Root>
The "CarInformation" node is the problem.
It starts and ends with '/>'.
This is how it should be:
<Root>
<CarInformation>
<DateOfBuilding>9/15/2006</DateOfBuilding>
<TimeOfBuilding>9:48:51 AM</TimeOfBuilding>
</CarInformation>
</Root>
This is my code:
class XMLWriter
{
XmlDocument xmlDocument = null;
string path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
XmlElement element = null;
XmlNode node = null;
XmlText text = null;
public XMLWriter()
{
this.xmlDocument = new XmlDocument();
this.xmlDocument.Load(path + "/file.xml");
}
public void WriteStartNodeAfterRoot(string startNode)
{
this.node = this.xmlDocument.CreateElement(startNode);
this.xmlDocument.DocumentElement.AppendChild(this.node);
this.xmlDocument.Save(path + "/file.xml");
}
public void WriteToXMLDoc(string elementString, string attribute)
{
this.element = this.xmlDocument.CreateElement(elementString);
this.text = this.xmlDocument.CreateTextNode(attribute);
this.xmlDocument.DocumentElement.AppendChild(this.element);
this.element.AppendChild(this.text);
this.xmlDocument.Save(path + "/file.xml");
}
public void WriteEndNodeBeforeRoot(string endNode)
{
this.node = this.xmlDocument.CreateElement(endNode);
this.xmlDocument.DocumentElement.AppendChild(this.node);
this.xmlDocument.Save(path + "/file.xml");
}
}
What am i doing wrong?
Thanks in advance!
|
|
|
|
|
You have to get away from the concepts you used when working with the XmlTextWriter. You're now working with the DOM and there is no thing such starting an element and then end it somewhat later.
You create an element, append it as child to some other element and if it should have some child nodes itself they have to be appended too. A good example is the WriteToXMLDoc method where you create an element, append it to the documents root element and afterwards append a text node to the element itself.
To get the wanted XML you have to append the elements created inside WriteToXMLDoc to the previously created carinformation element instead of the xmlDocument.DocumentElement. This will require some refactoring of your class but that shouldn't be too hard.
"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
|
|
|
|
|
Hi Stefan,
I refactored my class. I removed the 2 methods wich i don't need according to you.
This is how it looks like now:
class XMLWriter
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
XmlDocument xmlDocument = null;
XmlElement element = null;
XmlText text = null;
public XMLWriter()
{
this.xmlDocument = new XmlDocument();
this.xmlDocument.AppendChild(this.xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", null));
this.xmlDocument.Load(path + "/file.xml");
this.xmlDocument["Root"].AppendChild(this.xmlDocument.CreateElement("CarInformation"));
}
public void WriteToXMLDoc(string elementString, string value)
{
this.element = this.xmlDocument.CreateElement(elementString);
this.text = this.xmlDocument.CreateTextNode(value);
this.xmlDocument["Root"]["CarInformation"].AppendChild(this.element);
this.element.AppendChild(this.text);
this.xmlDocument.Save(path + "/file.xml");
}
}
This is how the output of the xml file looks like:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<CarInformation>
<DateOfBuilding>9/15/2006</DateOfBuilding>
<TimeOfBuilding>1:01:13 PM</TimeOfBuilding>
<DateOfBuilding>9/15/2006</DateOfBuilding>
<TimeOfBuilding>1:02:06 PM</TimeOfBuilding>
</CarInformation>
<CarInformation />
</Root>
It adds everything within the first "<CarInformation>".
What am i doing wrong this time?
Thanks in advance!
|
|
|
|
|
this.xmlDocument["Root"]["CarInformation"].AppendChild(this.element); The above line always successes the first found CarInformation node. Replacing it with the following should resolve the problem
this.xmlDocument.DocumentElement.LastChild.AppendChild(this.element);
"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
|
|
|
|
|
Hi Stefan,
That worked. You roxxx!
Thank you!
|
|
|
|
|
Hi All,
The application on which I am working has the following requirement:
1) Buttons are displayed as rows and columns in a panel
2) Panel AutoScroll property is set to true
3) On Mouse down on panel, user began to select the controls, A rectangle should be drawn based on mouse movement and the buttons with-in the rectangle should be selected
4) If scrollbar appears in the panel and if the user drags the mouse for selecting the controls, the scrolling should occur based on mouse movement
Your help in this will be needful.
Regards,
David
|
|
|
|
|
Best regards to all C# coders...
Plz I need your help in getting the right code snippet on how i can instantiate, set parameters and finalize a crystal report at runtime, in which the user has to define the parameters or what he wanna see in the report!
By the way, i guess i know how to set parameters and stuff, but i only need to know how to set and instantiate a crystal report programmaticaly.
Your help is much appreciated!
Knowledge Is KinG
|
|
|
|
|
Hi all,
I have a window service and I want to call it's methods by web service.But during calling it's method the service shows an error " The underlying connection was closed: Unable to connect to the remote server ".
I have created a setup of this window service which is I am calling through ServiceController in a web service.
I have checked all connections which are working properly.Please help me to solve this problem .If you can give an idea about how to call window service methods by web service then that will be appriceable.
Thanks in advance
Regards & Thanks
Sunil
|
|
|
|
|
Hi
how can i assign a list dynamically to the toolbar having style = "DropDownButton"
sAqIb
|
|
|
|
|
ToolBarButton b = new ToolBarButton();
b.Style = ToolBarButtonStyle.DropDownButton;
toolBar1.Buttons.Add(b);
"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
|
|
|
|
|
Thanks Stefan. I am using almost the same code to create and add toolbar buttons. But the questions was, how can i add a dynamic list to the above created toolbarbutton 'b'. (Suppose i am getting some values from a file and those values are supposed to be changed).
sAqIb
|
|
|
|
|
I'm not sure how this an be accomplished as I've never worked with ToolBar. Documentation of the ToolBarButtonStyle enumeration indicates that the code should follow this easy example:
MenuItem menuItem1 = new MenuItem("Print");
ContextMenu contextMenu1 = new ContextMenu(new MenuItem[]{menuItem1});
ToolBarButton b = new ToolBarButton ();
b.DropDownMenu = contextMenu1;
You'll have to create some more MenuItems and use the file values as text.
"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
|
|
|
|
|
Hi,
I have a form in my application on which a DataGrid and a tree view are present. The contents of the TreeView change with the change of the Row number of the grid. When i open the form for the first time, every thing is ok. When i close the form and then reopen it without closing my application, then the problem starts. On load, every thing goes fine, but when i select a different row, it gives exception with the message, ' Can't access disposed off object. Object name: TreeView'.' After this message the contents of the TreeView change accurately.
I am not disposing the tree view. Even in debug mode, when i check the contents of the treeview, it shows its contents correctly. But as soon as the statement containing that treeview executes, the exception is raised.
Any help, suggetion please...
Wasif Ehsan.
|
|
|
|
|
Hi,
I am working on a window based project.....
I am using VS 1.0 version...
I need to create combobox in a datagrid...
Can u help...
If possible send the code snippet...
Thanks in advance...
Regards,
Vaishali
|
|
|
|
|
Hi,
Regarding ur prob here is the solution...
============================================
Public Class Form1
Inherits System.Windows.Forms.Form
'Declare objects required to connect to the database
Private mcnSQL As New SqlClient.SqlConnection("SERVER=(local); INTEGRATED SECURITY=SSPI; DATABASE=northwind")
Private mdaEmploye As New SqlClient.SqlDataAdapter("SELECT TitleOfCourtesy, FirstName, LastName, Title FROM Employees", mcnSQL)
Private mds As New DataSet()
'We will also need a combo - After all, this is what we want to do!
Private mctlCombo As New ComboBox()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Connect the TextChanged event to a procedure
AddHandler mctlCombo.TextChanged, AddressOf Ctrls_TextChanged
'Fill ComboBox list.
With mctlCombo
.Name = "MyCombo"
.Visible = False
.Items.Clear()
.Items.Add("Sales Representative")
.Items.Add("Inside Sales Coordinator")
.Items.Add("Vice President, Sales")
.Items.Add("Sales Manager")
.Items.Add("Flunky")
End With
'Fill the dataset
mdaEmploye.Fill(mds, "Employees")
'Set the RowHeight of the DataGrid to the height of the ComboBox.
DataGrid1.PreferredRowHeight = mctlCombo.Height
'Give the data to the DataGrid
DataGrid1.DataSource = mds
DataGrid1.DataMember = "Employees"
'Add ComboBox to the Control collection of the DataGrid.
DataGrid1.Controls.Add(mctlCombo)
End Sub
Private Sub DataGrid1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles DataGrid1.Paint
'Set the width of the ComboBox to the Width of the cell
If DataGrid1.CurrentCell.ColumnNumber = 3 Then
mctlCombo.Width = DataGrid1.GetCurrentCellBounds.Width
End If
End Sub
Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
'Display (or hide) the ComboBox
If DataGrid1.CurrentCell.ColumnNumber = 3 Then
With mctlCombo
.Visible = False
.Width = 0
.Left = DataGrid1.GetCurrentCellBounds.Left
.Top = DataGrid1.GetCurrentCellBounds.Top
.Text = DataGrid1.Item(DataGrid1.CurrentCell).ToString & ""
.Visible = True
End With
Else
HideComboBox(sender, e)
End If
End Sub
Private Sub HideComboBox(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Scroll, DataGrid1.Click
'Hide the ComboBox when the grid is clicked or scrolled
mctlCombo.Visible = False
mctlCombo.Width = 0
End Sub
Private Sub Ctrls_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
'When the an item is selected, the grid must show this new value
If DataGrid1.CurrentCell.ColumnNumber = 3 Then
mctlCombo.Visible = False
If DataGrid1.Item(DataGrid1.CurrentCell).ToString & "" = "" Then SendKeys.Send("*")
DataGrid1.Item(DataGrid1.CurrentCell) = mctlCombo.Text
End If
End Sub
End Class
|
|
|
|
|
Sorry but i am working on C# .NET.....
can u help me in tht??
Thnaks.
Regards,
Vaishali
|
|
|
|
|
|
Hi
I have to implement a file upload progress bar while uploading the file to the server.
Can anyone please help !!!
Thanks in advance
|
|
|
|
|
I am using Visual Studio 2005 Professional Edition.
I have added a CrystalReport(.rpt) file to the project. I want to increase the width of this report at design. How can i do that?
Thanks.
|
|
|
|
|
Hi
I have a byte array[12].Iwant to convert it char or string and want to store in a char array.
How can i do this in c#.
for e.g
int bResult=fin.Read(m_pbytFileBuffer,0x0,0x50);//read 0x50 byte in buufer from file
for(bytSizeOfFolderName=1;m_pbytFileBuffer[bytSizeOfFolderName]!=0x00;bytSizeOfFolderName++)//calculate size of string
;
char []FolderName = new char[bytSizeOfFolderName+1];//dec char array
???????
Parshant
|
|
|
|
|
byte[] byteArray = new byte[12] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };<br />
string byteArrayInString = Encoding.ASCII.GetString(byteArray);<br />
char[] byteArrayInCharArray = byteArrayInString.ToCharArray();
|
|
|
|
|
Parshant Verma wrote: Iwant to convert it char
You can use following:
Array.Copy(<bytearray>,<chararray>, <no. of="" characters="" to="" copy="" from="" byte="" char="" array="">);
Regards,
Wasif Ehsan.
|
|
|
|
|
See here[^] maybe it is some helpful to you
|
|
|
|