|
Message Closed
modified 13-Feb-19 21:02pm.
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Yes, but nothing that will let him do that!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Well, technically, this terrible code would work:
switch (true)
{
case true when radioButton54.Checked:
...
break;
case true when radioButton122.Checked:
...
break;
case true when radioButton1.Checked:
...
break;
}
After all, you didn't say it had to be good code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
:shudder:
We should have a detector system that sends code like that direct to "weird and wonderful" so we can abuse it...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OW! MY EYES!
You will burn at the stake for coming up with such an abomination!
|
|
|
|
|
It's very useful code: a perfect example of "Just because you can do something, doesn't mean you should".
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Bloody hell you have a weird and twisty mind just to be able to think of that!
I'm with OG have it moved to weird and wonderful so it can be voted abuse
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I do not provide one-to-one solutions here: so sending me a private email requesting further help will not work.
If you want additional help please post the request publically, so all can assist and / or benefit.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
This is one of the many reasons I have email me switched off in my profile.
This space for rent
|
|
|
|
|
Why couldn't you simply set some variables in the Checked handler, which would make the switch statement irrelevant?
Paragraph q1 = null;
public void radio54_ischecked(...)
{
this.q1 = new Paragraph(string.Format("{0} {1}", label10Text, radioButton54.Text));
}
public void radio22_ischecked(...)
{
this.q1 = new Paragraph(string.Format("{0} {1}", label10Text, radioButton22.Text));
}
public void radio1_ischecked(...)
{
this.q1 = new Paragraph(string.Format("{0} {1}", label10Text, radioButton1.Text));
}
at that point, switch statement could be removed and replaced with this line of code, because q1 would already be ready (or null, depending on how your code is written):
if (q1 != null) pdfDosya.Add(q1);
EDIT ==================================
There are ways you can further reduce the code in the checked event handlers (depending on what framework you're dealing with), but I'll leave that as an exercise for the programmer.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 24-May-18 14:55pm.
|
|
|
|
|
Hello guys,
Im using .NET3.5 with ClosedXML libraray version is 0.75.0.0 .
I just inserted into merged cells on excel file. But when i convert to XPS file image is not in cell. Now image size is in pixel.
The questions are:
1. How to correctly insert image into merged cell?.
2. When i print file it's dependent on screen settings . How to solve this problem perfectly.
Thanks
|
|
|
|
|
|
Hi. I have a cellformatting event of a datagridview. No problem when loading and running first time. But what should i do if i click on a button and run cellformatting with this click. I couldnt manage this. Even i run databindingcompleted manually but it didnt help run cellformatting.
|
|
|
|
|
|
Hi. I try to color specific cells of a datagridview in cellformatting. everything is ok but if i color first row's cell, other rows' cells are coloured with the same color. so, for the time being i excluded to color first row. what should be the problem? this is the code:
if (e.ColumnIndex == 2)
{
if (dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString() !=bookmark_id.ToString())
{
if (dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() == ((int)specialStates.Anlasildi).ToString()) { dataGridView1.Rows[e.RowIndex].Cells["content"].Style.BackColor = Renk_Anlasildi_Backcolor; dataGridView1.Rows[e.RowIndex].Cells["content"].Style.ForeColor = Renk_Anlasildi_Forecolor; }
else if (dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() == ((int)specialStates.Onemli).ToString()) { dataGridView1.Rows[e.RowIndex].Cells["content"].Style.BackColor = Renk_Onemli_Backcolor; ; dataGridView1.Rows[e.RowIndex].Cells["content"].Style.ForeColor = Renk_Onemli_Forecolor; }
else if (dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() == ((int)specialStates.Soru).ToString()) { dataGridView1.Rows[e.RowIndex].Cells["content"].Style.BackColor = Renk_Soru_Backcolor; dataGridView1.Rows[e.RowIndex].Cells["content"].Style.ForeColor = Renk_Soru_Forecolor; }
}
}
|
|
|
|
|
Hi,
DataGridView may well be the most complex Control in the entire WinForms universe.
Cells have a DefaultStyle and a Style.
First row and/or first column may have different behavior (e.g. for column headers).
IMHO inside the CellFormatting handler you are expected to only alter the Value and the CellStyle fields of the DataGridViewCellFormattingEventArgs that is passed to you, and both apply to the cell that is invoking the handler.
If you need more than that, I'm afraid you may need to use explicitly created DataGridViewCellStyle objects for each cell you may want to alter the style of. You may want to start reading here: Cell Styles in the Windows Forms DataGridView Control | Microsoft Docs[^]
Anyhow, it may take quite some experimentation to tame the beast.
PS: if you don't have column headers right now, the easiest way out could well be to add them; that way you dont have actual data in row zero!
|
|
|
|
|
|
Thank you for your replies. Simply i didnt like cellformatting so i wrote my own function. I used a foreach and got all rows from datagridview and coloured related cells. I know it is against performence but this thing doesnt require much performence. Thanks again.
|
|
|
|
|
=-----------
<asp:GridView ID="GridView1" runat="server"
BorderStyle="Dashed" AutoGenerateColumns="False" onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:TemplateField HeaderText="T" HeaderStyle-Width="2%">
<ItemTemplate>
<asp:Label ID="lblBookID" runat="server" Text='<%# Bind("BID")%>'></asp:Label>
</ItemTemplate>
<blockquote class="quote"><div class="op">Quote:</div> </asp:TemplateField>
<asp:CommandField HeaderText="Cart" ShowHeader="True" ShowSelectButton="True" SelectText="Add to Cart"/>
</Columns>
</asp:GridView>
C# Code
---------------------------
//This code reads the selected row, and extract the
Quote:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
int x = 0;
x = Convert.ToInt32(GridView1.SelectedRow.Cells[0].Text);
Label2.Text = x.ToString ();
}
Current out put
-----------------
It displays nothing.
I tried many examples from the internet, but since my gridview is using item templates seem to gives me problems.
|
|
|
|
|
i have 3 text box (line1,line2,line3) and 3 button(button5,button6,button7) if i enter some text in line1 textbox and click the button5.the data will saved in line no 1 in notepad.if i enter some text in line2 textbox and click the button6.the data will saved in line no 2 in notepad.simillary for others textboxes.
private void button5_Click(object sender, EventArgs e)
{
var lineCount = File.ReadLines(@"H:\\specicied.txt").Count();
for (int i = 0; i < 1; i++)
{
using (StreamWriter objWriter = new StreamWriter(@"H:\\specicied.txt"))
{
//objWriter.Write(txtname.Text);
objWriter.Write(line1.Text + Environment.NewLine);
MessageBox.Show("Details have been saved");
}
}
}
private void button6_Click(object sender, EventArgs e)
{
var lineCount = File.ReadLines(@"H:\\My Application\\dd\\data.txt").Count();
for (int i = 1; i < 2; i++)
{
using (StreamWriter objWriter = new StreamWriter(@"H:\\specicied.txt"))
{
//objWriter.Write(txtname.Text);
objWriter.Write(line2.Text + Environment.NewLine);
MessageBox.Show("Details have been saved");
}
}
}
private void button7_Click(object sender, EventArgs e)
{
var lineCount = File.ReadLines(@"H:\\specicied.txt").Count();
for (int i = 2; i < 3; i++)
{
using (StreamWriter objWriter = new StreamWriter(@"H:\\specicied.txt"))
{
//objWriter.Write(txtname.Text);
objWriter.Write(line3.Text + Environment.NewLine);
MessageBox.Show("Details have been saved");
}
}
}
|
|
|
|
|
That's harder than you might think!
The problem is that text files don't have "lines" in the way you think of them: they just contain human readable characters one of which is interpreted by some - but not all - applications as an "end of line" character.
So you can't "write to line 2" because it isn't at a fixed place - where line two starts is immediately after the end of line character indicating the end of line one. And you can't "insert" to a text file, as when you write it will overwrite the existing characters.
So instead of that, read all the lines from your file when your app starts:
private string[] lines;
...
lines = FileReadAllLines(pathToFile); Then when you want to change line 1:
lines[0] = line1.Text;
File.WriteAllLines(pathToFile, lines); And the same for line 2:
lines[1] = line2.Text;
File.WriteAllLines(pathToFile, lines);
BTW: Do yourself a favour, and stop using Visual Studio default names for everything - you may remember that "TextBox8" is the mobile number today, but when you have to modify it in three weeks time, will you then? Use descriptive names - "tbMobileNo" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbMobile" in three keystrokes, where "TextBox8" takes thinking about and 8 keystrokes...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
modified 19-May-18 11:33am.
|
|
|
|
|
Do yourself another favor. Do not refer to writing a text file as "in notepad". Notepad is an application that edits text files, not a file itself.
|
|
|
|