|
God what a dogs breakfast
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
Interfaces are somewhat lame, but needed; extensions work here and there; inheritance is "bad". I think it provides some middle ground.
If it avoids having to implement every interface member, all the time, that's good too.
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
|
|
|
|
|
using Framework 4.8, WinForms (classic).
I'm doing some complex run-time stuff with a TableLayoutPanel in a UserControl ... adding, replacing Controls, resizing columns, changing ColumnSpans ... even though the UserControl is double buffered, as well as its hosting Form (site) ... the usual bracketing in Suspend/Restore-Layout blocks does not prevent cascades of spastic stuttering.
But, one little dose of good old CreateParams
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle = cp.ExStyle | 0x2000000;
return cp;
}
} I thought that had gone extinct with other VB-heritage dinosaurs like 'DoEvents.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
modified 18-Aug-21 2:05am.
|
|
|
|
|
Yeah, I've had to use it occasionally as well: Disable the Close box on a form[^]
But ... at least MS provided a nice, easy way to do something they didn't think you'd ever want to!
If they hadn't ... it would have been a real PITA.
"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!
|
|
|
|
|
OriginalGriff wrote: MS provided a nice, easy way to do something they didn't think you'd ever want to! As opposed to the method they've provided in Weleven for changing your default web browser.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi,
I don't remember what the state/quirks of WinForms was in 2012, when you wrote that tip, but, it is possible to toggle the visibility of the ControlBox at run-time by setting its boolean value.
Of course, yes, hide the ControlBox, and the max/min buttons and the icon/menu, vanish.
However, I'd find it quite strange to have those control widgets disappearing, reappearing
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
database db = new database(); DataTable tbl = new DataTable();
private void AutoNumber()
{
tbl.Clear();
tbl = db.readData("Select max (Des_ID) from Deserved", "");
if ((tbl.Rows[0][0].ToString() == DBNull.Value.ToString()))
{
txtID.Text = "1";
}
else
{
txtID.Text = (Convert.ToInt32(tbl.Rows[0][0]) + 1).ToString();
}
NudPrice.Value = 1;
DtbDate.Text = DateTime.Now.ToShortDateString();
txtNotes.Clear();
btnAdd.Enabled = true;
btnNew.Enabled = true;
btnDelete.Enabled = false;
btnDeleteAll.Enabled = false;
btnSave.Enabled = false;
|
|
|
|
|
|
The error says that there are either no rows or no columns in your Rows collection:
And why that might be is not something we can help with: we have no access to your database class, or its readData method, or the data behind it.
So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
But you do have to ask yourself why you are going at this in such as "round the houses" approach: creating and filling a DataTable for a single numeric value looks rather silly, when every SQL based system I have ever met has supported an ExecuteScalar method to query and return a single value ...
"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!
|
|
|
|
|
Hi,
I want to detect index of all empty values in a list using Linq. I searched StachOverFlow to find a solution. I changed it based on my needs. The following Linq method syntex works fine:
List<string> collection = new List<string>() {"", "ghjg", "jkgh", ""};
var indexOf = collection.Select((value, index) => new { value, index })
.Where(pair => string.IsNullOrEmpty(pair.value))
.Select(pair => pair.index);
foreach (var item in indexOf)
{
Console.WriteLine(item);
}
I tested it in LinqPad.
But I need an explanation about how Linq detects index in the defined pair?
|
|
|
|
|
|
Hello.
I use C# in Visual Studio and need to work with Excels spreadsheets. I know how to create and save the spreadsheets, but I need to format the plan, like to define the cell color, a collumn width and so on. Can anyone tell me how to access the commands in Excel through C#?
Thanks.
|
|
|
|
|
|
|
You can use the Range[^] class to refer to rows, columns and cells. You can add formatting, formulas etc through these objects. I have a sample application that contains the following sequence to control a range of cells:
cellRange = worksheet.get_Range("D2", "D6");
cellRange.Formula = "=RAND()*100000";
cellRange.NumberFormat = "£#,##0.00";
There are a number of websites run by Excel experts that offer help which Google can find for you.
|
|
|
|
|
I use the EPPlus lib. Gives me full control
|
|
|
|
|
Hi.
I use C# in Visual Studio and use Forms. I need to generate an Excel file with merged columns. I tried the following code:
private void button1_Click(object sender, EventArgs e)
{
string Arquivo = @"D:\Diversos\Antares\Relatório.xlsx";
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Range[ws.Cells[1, 1], ws.Cells[1, 4]].Merge();
xlWorkSheet.Visible = XlSheetVisibility.xlSheetVisible;
xlWorkSheet.Cells[1, 1] = "Dados do cliente:";
xlWorkBook.SaveAs(Arquivo, Excel.XlFileFormat.xlWorkbookDefault, misValue, misValue, misValue, misValue,
Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
}
Of course, it's just a try and much code is missing, but the essencial is here. When I run this program I receive the message: "System.Runtime.InteropServices.COMException: 'Não há suporte para esta interface" The last piece of the message means "There's no support for this interface", at the line of the merge.
Can anyone help me solve this problem? If you have other suggestion on how to inteact with Excel, I'd appreciate it.
Thanks.
modified 12-Aug-21 18:54pm.
|
|
|
|
|
I have just tried this and it works correctly. However I notice a possible error in the following line of code:
xlWorkSheet.Range[ws.Cells[1, 1], ws.Cells[1, 4]].Merge();
where is ws defined?
|
|
|
|
|
Hi, Richard.
You are right. There was a problem in my definition. I correct it and the problem with merge disappeared. The spreadsheet is created correctly, but I could not make it appear. I changed the routine to the formload event. See the code:
private void Form1_Load(object sender, EventArgs e)
{
string Arquivo = @"D:\Diversos\Antares\Relatório.xlsx";
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Range[xlWorkSheet.Cells[1, 1], xlWorkSheet.Cells[1, 4]].Merge();
xlWorkSheet.Visible = XlSheetVisibility.xlSheetVisible;
xlWorkSheet.Cells[1, 1] = "Dados do cliente:";
}
The problem now is that I can't make the spreadsheet visible. The line:
xlWorkSheet.Visible = XlSheetVisibility.xlSheetVisible;
appears not to work. Do you know what I must do to correct it?
Thanks.
|
|
|
|
|
I have just tried that and it works fine. But I think you may first need to make the application visible, so the sequence should be:
xlApp.Visible = true;
xlWorkSheet.Visible = XlSheetVisibility.xlSheetVisible;
|
|
|
|
|
Richard.
Great hint. It worked fine. One more thing: suppose I want to save this file in a button. When I click the button, C# must verifiy if it is running. How do I do this?
Thanks a lot.
modified 14-Aug-21 20:02pm.
|
|
|
|
|
You are welcome. I also learned a few things myself.
|
|
|
|
|
I have a string variable as follows:
String str = "dt.Rows[i][3]";
I want to use that string variable in a For loop:
For (int i=0; dt.Rows.Count; i++)
{
str;
}
How is it possible to pass i from the string to For loop?
modified 12-Aug-21 6:07am.
|
|
|
|
|
I might be being really thick here but I can't see what you're wanting to do with that string in your loop. It must serve some purpose, so what is it that you are trying to do with it? BTW, I assume your for statement actually means to read:
for(int i = 0; i < dt.Rows.Count; i++)
|
|
|
|
|
That's a really mysterious question, because that normally "Just Works(tm)". There isn't really any "passing", you just use the string in the for loop and it works. Unless there's something critical aspect of the code that prevents that which you haven't shown.
The string "dt.Rows[i][3]" looks suspiciously like it's supposed to have some deeper meaning, but it doesn't actually, it's just a string. You could store dt and 3 in some variables though.
modified 12-Aug-21 8:57am.
|
|
|
|
|