|
The problem coexists with DataTable is that I cannot change text font of cells. And because of the language I'm using (Persian), I need to perform RightToLeft function. It's so easy in DataGridView's native properties but I don't know hpw to change font, alignment, and RightToLeft properties in DataTable.
|
|
|
|
|
That's a presentation function, not data related - and should be solved separate to the data by setting the default cell style (including font) on the DGV before or after you load the data.
You are mixing this stuff up far too much: if you need to change from a DGV to different controls, that formatting will not carry with it anyway!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
The problem coexists with DataTable is that I cannot change text font of cells. And because of the language I'm using (Persian), I need to perform RightToLeft function. It's so easy in DataGridView's native properties but I don't know hpw to change font, alignment, and RightToLeft properties in DataTable.
|
|
|
|
|
Listen to what OG is saying, treat the data and the formatting/presentation as two distinct issues. Store the underlying data set, probably as CSV in the users data folder and format the DGV using the DGV properties when loading the stored data.
DO NOT ATTEMPT TO STORE THE FORMATTING!
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
I have a .NET 5 console app, which has an App.config (with EF / database connection strings in it).
It works fine, but if I publish as a single file it doesn't work, i.e. it doesn't read the app.config file..
I even specified that the App.config is not embedded in single file deploy, like so in the .csproj
<ItemGroup>
<None Update="*.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</None>
</ItemGroup>
What else could I be missing!?
|
|
|
|
|
Are you sure it's renaming the config file correctly? With that setting, it looks like the file in the output directory will be called app.config , but it needs to be called YourApp.dll.config or YourApp.exe.config .
What happens if you remove the <None> element from the project file?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
yea, yeah, once deployed, with that flag / .csproj change, it has both files, i.e. "app.config", and "<myproj>.dll.config" but fails to read any of them anyway!
|
|
|
|
|
There is no "App.Config" at runtime; it's xxx.exe.config.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Surely you mean <project name>.dll.config? (.net core and .net5, remember!)
Which is the one I have, obviously! VS didn't do any joke on me!
But, just to be sure I did rename it <project name>.exe.config, didnt run either
This seems to be very specific to single file deployment btw, I think you missed that.
|
|
|
|
|
In my case, the "build" creates it in the Debug and Release folders. One doesn't simply rename something.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Are you trolling?
If not, you are not helping.
Word of advice, get familiar with Visual Studio or MSBUILD. It does all the trivial renaming and such for you, there is no ambiguity except in your mind.
Also get familiar with .net core / 5.
it's .DLL.config.
UNLIKE .NET Framework 4 and before, which was .exe.config
modified 18-Nov-20 6:32am.
|
|
|
|
|
Got you.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I have a bunch of messages in a Constants file that I want to convert all string constants for messages displayed to users to be moved to a localized/globalization resource file.
I created a Resources.resx file and I'm trying to figure out how to reference a resource in a controller. For example this resource in my Resources.resx file
internal static string ExamItemResponseAddSuccessfully {
get {
return ResourceManager.GetString("ExamItemResponseAddSuccessfully", resourceCulture);
}
}
I want to reference it in a controller POST action to replace the bolded reference to the string constant in the method below. How do I reference the resource above in the method below.
public async Task<IActionResult> CreateDorItemResponse(CreateEditDorItemResponseViewModel dorToCreateItemResponse, CancellationToken cancellationToken)
{
var newDorItemResponse = new DorItemResponse();
if (ModelState.IsValid)
{
try
{
var item = await _dorService.GetItemAsync(dorToCreateItemResponse.ItemId, cancellationToken)
.ConfigureAwait(true);
_mapper.Map(dorToCreateItemResponse, newDorItemResponse);
newDorItemResponse.CreatedBy = User.Identity.Name;
newDorItemResponse.ModifiedBy = User.Identity.Name;
await _dorService.CreateEditItemResponse(newDorItemResponse, User.Identity.Name, cancellationToken).ConfigureAwait(true);
TempData.Put(TempDataKey.Dor.RESPONSE_ADD_MESSAGE, StatusMessageModel.Create(Constants.Dor.RESPONSE_ADD_SUCCESS, false));
return RedirectToAction(nameof(EditDorItem), new {id = item.ItemId, dorId = item.DorId});
}
catch (Exception)
{
TempData.Put(TempDataKey.Dor.RESPONSE_ADD_MESSAGE, StatusMessageModel.Create(Constants.Dor.RESPONSE_UPDATE_FAIL));
}
}
return View(dorToCreateItemResponse);
}
|
|
|
|
|
Something like this should work:
TempData.Put(TempDataKey.Dor.RESPONSE_ADD_MESSAGE, StatusMessageModel.Create(Properties.Resources.ExamItemResponseAddSuccessfully, false));
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: TempData.Put(TempDataKey.Dor.RESPONSE_ADD_MESSAGE, StatusMessageModel.Create(Properties.Resources.ExamItemResponseAddSuccessfully, false));
I'm trying to replace the TempData.Put(TempDataKey...) stuff because I that is in the Constants file and I'm getting rid of that altogether.
I want to have the message come from the Resources file.
|
|
|
|
|
As far as I can see from your question, the values in the TempDataKey class represent the key of the TempData item. The message constants are defined in the Constants class, which is why I replaced that constant with the value from the resource file.
The TempData key will never be shown to the user.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello - I am constructing an URL to pass for API call.
It has a date value in it.
DateTime.Today.AddDays(0).ToString("yyyy-MM-dd")
Is there some way I can pass the (0) dynamically, reading from App.Config file?
I tried --
DateTime.Today.AddDays(ConfigurationManager.AppSettings["CompletedDays"].ToString("yyyy-MM-dd") which errored out and did not work. Any way to do this?
Thanks!
|
|
|
|
|
Member 14474607 wrote: which errored out and did not work. Sorry, there is no way we can guess what that means. Please edit your question and provide proper details of the problem.
|
|
|
|
|
var revisedDateTime = DateTime.Now.AddDays( (int) ConfigurationManager.AppSettings["CompletedDays"] );
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
The AppSettings indexer returns a string . The code will compile, but will throw an InvalidCastException at runtime.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
50-50 chance. There are some value-object pair settings out there (UWP: ApplicationDataContainer)
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
|
If you want to get picky, AppSettings is based on a NameObjectCollectionBase.
Not my fault it's protected. But I won't whine about it.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
int completedDays;
int.TryParse(ConfigurationManager.AppSettings["CompletedDays"], out completedDays);
return DateTime.Today.AddDays(completedDays).ToString("yyyy-MM-dd"); Int32.TryParse Method (System) | Microsoft Docs[^]
If the setting isn't a valid integer, completedDays will be set to 0 . If you want to validate that the setting is valid, check the return value of TryParse .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
A much better way of doing things Richard - I often overlook TryParse and default to using one of the ConvertToxxx static methods
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|