|
I'm developing an application with a PropertyGrid.
The instance of the class I'm setting as the SelectedObject for the PropertyGrid contain an enum. This works great as the PropertyGrid automatically generates a ComboBox for the enum, letting the user choose any of the enum's elements.
But I'm forced to store the elements in a file and not in an enum. So the file can be changed without needing to compile the entire application. Also each element may also have spaces which enums don't support.
I'm unable to find a find a solution for this. I'm also afraid that this is impossible to do...
I have basically a file with this content:
Energy kW
Energy 10*kW
Energy 100*kW
The class I want to display in the PropertyGrid might look like this:
class PhysicalUnit
{
int value;
string[] units;
public int Value
{
get { return value; }
set { this.value = value; }
}
public string[] Units
{
get { return units; }
set { units = value; }
}
}
In this example I have assumed that the string[] units contains all elements from the file. When assigning an instance of the class to a PropertyView I would like to select a unit. Of course this don't work because I don't have a container object to hold the selected unit. Also the PropertyView don't create a ComboBox of the string[]. It appears that each GridItem in the PropertyGrid don't create a similar selection for arrays as enums.
If I make an enum of the units...
enum Units
{
EnergykW,
Energy10kW,
Energy100kW
}
...and create an instance member of the enum in the class with a public property, the PropertyView would automatically create me a ComboBox to select the elements and store what element I selected.
Any solution?
|
|
|
|
|
A (custom?) UITypeEdit would help;
class PhysicalUnit
{
int value;
string units;
public int Value
{
get { return value; }
set { this.value = value; }
}
[Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]
public string Units
{
get { return units; }
set { units = value; }
}
} I don't think you want a mulilinestring editor, but if you split the string on the linebreaks you'll have a string[]. There's a colourfull example here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Your code didn't work.
I ran the sample you linked. The PropertyView seemed to use enums. I don't understand either how example would help me
Any other solution?
modified 12-Jun-14 8:48am.
|
|
|
|
|
Mc_Topaz wrote: Your code didn't work.
That's very descriptive. Did it fail to compile, did it throw an exception, or did it fail silently? Which code, the snippet I provided, or the code from the article?
Mc_Topaz wrote: I ran the sample you linked. The PropertyView seemed to use enums. I don't understand either how example would help me It's an article that explains how to put your own editor in the property-grid.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Sorry for that!
The PropertyView display the string[] property but the value of it is "String[]-matrix".
I cannot see the three elements I specified to the string array.
The value is also read-only.
That's the status right now
|
|
|
|
|
I recently found this post: http://bytes.com/topic/c-sharp/answers/822620-simple-string-list-property-grid[^]
Which instructed to use:
[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
This result is: The value is still "String[]-matrix". But I can expand the property and see the elements by it's index [0], [1] and [2]. Each element have the assigned value.
Still this is not what I wanted. I Would like to select the elements in the array and the value should be what element is selected.
/Steffe
|
|
|
|
|
|
30 minutes well spent
Each type that you want to edit will need a specialized UITypeEditor. If none exists for the type, you have to write one yourself. That's what the VB.NET example shows.
The snippet I posted was aimed at a single string; you'd have to split it into an array by hand again.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
how to create automatically generate unique id based on year add year in grid view control footer row c#
|
|
|
|
|
Nishant's not here right now. Please leave a message and he'll get back to you.
*Beep*
|
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
So what have you tried?
Where are you stuck?
And (as Pete says) who is Nishant?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
how to automatically generate unique id based on year when i add year in grid view control footer row in c#
|
|
|
|
|
That depends. What does year represent here? If you want to use a completely unique id and you can use a string for it, create a new Guid and put the year at the start. Something like this:
private string CreateUniqueId(int year)
{
Guid myGuid = Guid.NewGuid();
return string.Format("{0}-[1}", year, myGuid.ToString("D"));
}
|
|
|
|
|
sir i am use gridview control for save new records by footer row when i add year in records then automatically generate year wise unique id plz help
|
|
|
|
|
Don't.
You shouldn't generate unique ids until you actually store the information - up to that point it is subject to change because there may well be other people adding data to the same database. So use the database itself to generate your unique value.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
|
sir i create a application on employee detail i will showing employee records date wise between two calender control from last year to till date plz help
|
|
|
|
|
I am using Google plus authentication in MVC5, at first time login it is working properly but when login next time than in function ExternalLoginCallback the function GetExternalLoginInfoAsync() return null value of loginInfo. Please help me what is the problem. code is give bellow.
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Index", "Error");
}
else
{
return RedirectToAction("Index", "Home");
}
}
|
|
|
|
|
Hi,
This has been driving me mad all week, so finally I gave in an am posting for some help. I am a budding c# programmer and have made lots of simple programs. Every time I decide to try something new, something crops up that I can't yet solve.
I am trying to make an editor for syncing srt subtitle files. I can load the subtitle file, I can send it to a textbox if i want to, i can trim and split the time line and send them to different places, but I am having difficulty processing it as a whole.
I practiced splitting and trimming the time line when i had the text string in a textbox just to make it simple. The srt file is structured like:
1
00:00:01,151 --> 00:00:03,432
Subtitle Line 1
2
00:00:05,651 --> 00:00:07,238
Subtitle Line 1 sub 2
Subtitle Line 2 sub 2
3
00:00:08,751 --> 00:00:10,065
Subtitle Line 1 sub 3
etc etc etc
I placed the "00:00:01,151 --> 00:00:03,432" line in textBox1 and using the code:
string startTime = textBox1.Text;
string result = startTime.Substring(0, theString.IndexOf("-->")).Trim();
textBox4.Text = result;
int index = textBox1.Text.IndexOf('>');
string result2 = textBox1.Text.Substring(index + 2);
textBox5.Text = result2;
This code puts each part into separate text boxes and works as i want.
I have a good handle on logic code and can understand what i need to do, but not how to do it.
-I need to read the line and if it contains only an integer, send it to column 1.
-I need to read the line and if it contains '-->' use the above code and send it to cols 2 and 3.
-I need to read the next line and send it to col 4 (1st subtitle text line, will always contain text)
-I need to read the line and if it is blank, make a new row, else append the text to the text in column 4 and then make new row. Then start over.
Logically, i know what to do, but i am having trouble with looping through and processing each line.
Does anyone have any tips that could help me? Thanks
> Load "Stumped",8,1
|
|
|
|
|
This is just a question of reading each line of the file and taking a different path based on the content of each line, as you have described above. Something like:
WHILE NOT EOF
BEGIN
READ nextline
IF nextline == singleinteger THEN COPY nextline to Column1
ELSEIF nextline.CONTAINS("-->")
BEGIN
CALL processDateFields
WHILE TRUE
BEGIN
READ nextline
IF nextline == BLANK THEN BREAK
APPEND nextline to Column4
END
ADD ROW to GRID
END
END
Obviously you will need to add some other tests for garbage data, repeated blanks etc., but this should give you a starting point.
|
|
|
|
|
Thanks, this gives me more to think about
|
|
|
|
|
I would create a class SubTitle with properties number, startTime, EndTime, etc. Then create an object SubTitle, fill the properties and add the object to a List<subtitle> collection, and so for all subtitles in the file. Finally, set the collection to be the datasource of the datagrid.
|
|
|
|
|
I hadn't thought of that, I will add it to my testing. Thanks
|
|
|
|
|
I have a label that is based on a conditional statement, however, the condition is not acting correctly, for instance knowing that the following should be true:
A==1?"First":A==2?"Second":"Final"
Given 1, you see "First"
Given 2, it shows "Final"
Given any other number it shows "Final"
I need it to show "Second"
Now you see the pseudo code, here is the actual code:
<asp:Label ID="lblActive" runat="server" Text='<%# Convert.ToInt32(Eval("Active"))==1?"Active":Convert.ToInt32(Eval("Active"))==2?"Exempt":"Inactive" %>'></asp:Label>
Why is it always showing "Inactive" when clearly the eval is 2 or 1, I expected all the 0's to be Inactive and they are, but all 1's are active and all 2's are showing "Inactive"
|
|
|
|