|
Hello all,
how to insert a space with patten matching in c#?
I need to find a string "[a-z][0-9]xyz"
and insert a space before "xyz" how can we achieve?
E.g.
"bddd"
should be changed to
"b ddd"
Character at place "b" can be anything but "ddd" will be static.
Can i use regular expression?
Thanks
|
|
|
|
|
Member 2324483 wrote:
Can i use regular expression?
You could take the regex pattern (?<word>\w*)ddd and use the replace pattern ${word} ddd
Regex.Replace(someString, @"(?<word>\w*)ddd", "${word} ddd")
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
thanks that perfectly worked. I used it for single non-space character like below:
<code>Regex.Replace(someString, @"(?<word>\S)ddd", "${word} ddd")</code>
|
|
|
|
|
Today i was attempting (for the first time) to make a simple application that will allow me to read XML file into Grid View control (via DataSet), and later on save back any changes back to xml file (Win forms application).
For time being i'm "ignoring" the "save" part, as i'm not able even to get the "view/load" part to work proerply, so i will try to get that working later on once i fix the initial problem i'm seeking help for.
I've tried something thats throwing me exception but since i've never tried binding a dataset to XML i'm probably doing something stupid or missing something...
i've made simple xml file (named it: XMLFile1.xml) with the following content:
<?xml version="1.0" encoding="utf-8" ?>
<item_list>
<item>
<title>item 1</title>
<des>item 1 description</des>
</item>
<item>
<title>item 2</title>
<des>item 2 description</des>
</item>
</item_list>
on the form i added:
1. button with default name of button1.
2. DataGridView with default name of dataGridView1.
3. DataSet with default name of dataSet1.
inside the data grid i've created 2 columns with names "title" & "des".
finally created click event for button with the following:
private void button1_Click(object sender, EventArgs e)
{
string xmlPath = @"..\..\XMLFile1.xml";
dataSet1.ReadXml( xmlPath, XmlReadMode.ReadSchema );
dataGridView1.DataMember = "item";
}
Now the problem i have is the line:
dataGridView1.DataMember = "item";
is thowing exception of "Child list for field item cannot be created".
The truth is i'm not sure if this error is result of invalid xml file i've created, or i'm not using properly the DataMember property.
I would appreciate if anyone could help me & point me in right direction of what i'm doing wrong here.
best regards,
Idan B.
"Assumptions is the mother of all f***ups"
|
|
|
|
|
I just quickly browsed your post, so I may be way off on the answer, but it looks like you are on the right track.
DataSet dsXml = new DataSet();
dsXml.ReadXml(fileName);
Within a DataSet you can have multiple DataTable objects depending on the format of the XML. What I've done in the past is to create a dynamic combo box that gets the name of every single table in the DataSet.
You would want to set the DataSource of you DataGridView to the DataSet object we read (dsXml). Then when your combo box changes you can set the data member to the name of the selected item.
private void LoadComboBox()
{
foreach (DataTable tbl in dsXml.Tables)
{
ComboBox1.Items.Add(tbl.TableName);
}
}
private void SetSource()
{
DataGridView1.DataSource = dsXml;
}
private void OnComboChanged()
{
DataGridView1.DataMember = ComboBox1.Text;
}
You could also set the source to a specific table in the DataSet.
DataGridView1.DataSource = dsXml.Tables[0];
|
|
|
|
|
Thank you very much for your reply.
While i was reading your reply, i came aware of the Tables[] collection and assigning the Tables[0] was half of the solution for my problem.
i had in my code 2 problems:
1. Seems columns werent created properly.
Adding this line:
dataGridView1.AutoGenerateColumns = true;
Solved it. Wierd thing is i had already 2 coulmns with names "title" & "des".
2. As mentioned in begining, nothing was showing up on GridView, till i've pointed DataSource to be Tables[0].
Solution looks like this:
private void button1_Click(object sender, EventArgs e)
{
string xmlPath = @"..\..\XMLFile1.xml";
dataSet1.ReadXml(xmlPath);
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = dataSet1.Tables[0];
}
EDIT:
I found why the columns i previously added wouldnt show up the values i wanted.
Previously neglected to set on the column the DataPropertyName to "title" & "des" as well.
I wrongly assumed that the "name" of field was enough.
With the DataPropertyName set properly, code looks like:
private void button1_Click(object sender, EventArgs e)
{
string xmlPath = @"..\..\XMLFile1.xml";
dataSet1.ReadXml(xmlPath);
dataGridView1.DataSource = dataSet1.Tables[0];
}
the only problem was need to set source to table 0.
"Assumptions is the mother of all f***ups"
modified on Thursday, December 18, 2008 11:30 AM
|
|
|
|
|
Instead of: dataGridView1.DataMember = "item";
try: dataGridView1.DataMember = "item_list";
|
|
|
|
|
thanks for your reply.
I'm afraid that solution does not work. This also result with "Child list for field item_list cannot be created." exception.
See my reply to the other answer given to me, that helped me find the solution to problem.
Solution involved setting dataSource to first table only (Tables[0]) (and i've also neglected to set DataPropertyName before which was also the problem).
"Assumptions is the mother of all f***ups"
modified on Thursday, December 18, 2008 11:31 AM
|
|
|
|
|
greetings!
I'm trying to work with C# and with ZIP files. How can I do that? for example: I have a path of a ZIP file and I want to know: the size of the file,the size of the file before Zipping,
is there any simple way of doing this?
thank you!
|
|
|
|
|
Depends, I think newer versions of C# have *some* zip functionality built in, but even then, I doubt they can tell you the size of files inside the zip, without first unzipping it.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Christian Graus wrote: I think newer versions of C# have *some* zip functionality built in
It's in the Base Class Library System.IO.Packaging
led mike
|
|
|
|
|
There is an open-source library for working with zip files: #ziplib[^]
Regards,
Lev
|
|
|
|
|
I tried to add one annotation to the place where mouse click in the chart control.
but not sucessesful, anyone has a idea?
|
|
|
|
|
Hello,
I have been using Visual Studio Professional for a long time and I now I want to start using Visual Studio 2008 Team System. I got this software free from my university and now I want to install it on my laptop. I have Vista installed and also I got SQL Server 2005 express. Will I be able to install VSTS on my laptop ? or Do I need buy SQL Server as I was thinking, It would be great if VSTS works on SQL Server Express 2005 ? Do I need to buy SharePoint software or it comes with VSTS for free ?
Thank you very much.
|
|
|
|
|
VSTS requires a server running Windows Server, not XP or Vista. You also need a SQL Server Enterprise license. Sharepoint also doesn't come with VSTS.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thank you for your reply.
So, what would be the best solution for a very small size version control system which fits on my laptop and that can be run on SQL Server Express without requiring IIS or may be requiring IIS ? I would love to get a source control software which can be integrated to Visual Studio 2008. I have heard about Fortress, but I am not sure if that supports VS 2008. Would you please give me any idea ?
Regards
|
|
|
|
|
Most things integrate with Visual Studio. I still think that Sourcesafe is fine for the sort of setup you're talking about.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Good evening all,
I have a form with a number of controls on it. In particular - some buttons and a 'TabControl'
In the form designer, when i double click on a button, i can code an event to fire, like below,
private void button1_Click(object sender, EventArgs e)
{
}
I would like t be able to do the same when the user clicks on one of the tabs of my TabControl, however i can seem to find a way to trigger an event like i do with a button.
For example - if i double cick on the tab in the designer view - nothing happens.
Can anyone help ?
Regards
Neil
|
|
|
|
|
Check out the events in the properties window for the control. You have click, doubleclick, etc.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi,
TabControl.SelectedIndexChanged is the right event for you; you may want to include a switch in its handler if you need to run different code snippets for different tab pages.
|
|
|
|
|
Thank you Luc,
So can you please give me some guidance as to how i would then use this to make some.....labels or checkboxes appear for instance ?
I have trid a few things but it seems quit a dfficult control to use.
Thanks
Neil
|
|
|
|
|
As John pointed out, the easiest way to handle a TabControl in Visual Designer is to create one UserControl per tabpage; i.e. first create the UserControls you want, then create a TabControl on your form and instantiate the UserControls on the individual pages.
An alternative, not that popular though, is to create the Controls by run-time code.
|
|
|
|
|
unfortunatley i'm completely new to programming so all that means very little to me.
Its my first time trying a tabControl, i have created & tested all my buttons to go on it, i just needed other things to appear on the form when user chose the varius tabs on the form.
I'm kind of thinking i've bitten off more than i can chew ?
I'll have a look for infon on 'UserControls' and see what i can find.
Many thanks
Neil
|
|
|
|
|
Hi,
You do not need UserControls if they are new to you: you can design a TabControl in Visual Designer without UserControls, just click on the tab to show an individual tab page (you may have to try a couple of times to get the page you want), then fill it as usual. IMO it is easier with UserControls though (only if you are used to them that is).
|
|
|
|
|
Hi Luc,
Sorry - i know this is dragging on a bit.
I have the tab control functional and populated with my controls already, what i want to do is make some other controls (check boxes etc) appear on the page when the user clicks on a tab.
I can code an event if i double click on the page of the tab (in designer) but that doesn't help work. I want the event to run when the user clicks on the tab. It's not the same as clicking on the tab page.
Hope this makes sense !
|
|
|
|