|
OriginalGriff wrote: Use the "Improve question" widget Good luck to him trying to find it.
|
|
|
|
|
Well, he should post in the right forum then!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I have a area in my Project where i need to display a title and content in two text boxes. The Data base tables are:
ID | Title | Content
This is what I have so far, I know I am on the right track, I just cant figure out how to get each box to display based on the ID.
[CODE]
private void frmMain_Load(object sender, EventArgs e)
{
try
{
string connStr = ConfigurationManager.ConnectionStrings["sdcAssistDB"].ConnectionString;
OleDbConnection dbConn = new OleDbConnection(connStr);
dbConn.Open();
OleDbCommand dbCommand = new OleDbCommand();
dbCommand.Connection = dbConn;
string query = "select * from JobAid";
dbCommand.CommandText = query;
OleDbDataReader dbReader = dbCommand.ExecuteReader();
while (dbReader.Read())
{
txtTitle1.Text = (dbReader["Title"].ToString());
txtContent1.Text = (dbReader["Content"].ToString());
txtTitle2.Text = (dbReader["Title"].ToString());
txtContent2.Text = (dbReader["Content"].ToString());
}
dbConn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Unable to Connect to Database" + Environment.NewLine + "SDC Assistant will now Close " +ex,
"Critical Database Error!",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
Application.Exit();
}
}
[/CODE]
Thank you in advance
Rab
|
|
|
|
|
Um.
You do realise that the loop
while (dbReader.Read())
{
txtTitle1.Text = (dbReader["Title"].ToString());
txtContent1.Text = (dbReader["Content"].ToString());
txtTitle2.Text = (dbReader["Title"].ToString());
txtContent2.Text = (dbReader["Content"].ToString());
} will always leave the final row's worth in the text boxes, regardless of how many you return from SQL? I'd suggest replacing the while with if
And to make it do what you want, change this:
string query = "select * from JobAid";
dbCommand.CommandText = query;
To this:
string query = "SELECT * FROM JobAid WHERE Id=@ID";
dbCommand.CommandText = query;
dbCommand.Parameters.AddWithValue("@ID", yourIdValueToLookFor);
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I am writing a c# dll to Revit. I use the Util static class in the code ex.
Util.PluralSuffix(n)
but it seems that Util is not known to the visual c#.
What is I am missing?
brgrds
|
|
|
|
|
Hi brgrds,
The bit that is missing is the ability to understand the section at the top of this forum, i.e. the rules for the lounge.
They may help you in your quest for world dominance.
|
|
|
|
|
You're missing the right place to post the question.
Try here[^] for more specific answers or here[^] if you want more of a discussion.
Wrong is evil and must be defeated. - Jeff Ello
(√-sh*t) 2
|
|
|
|
|
Member 8902328 wrote: I use the Util static class in the code ex. What Util class?
Member 8902328 wrote: but it seems that Util is not known to the visual c#. Because there is no class with that name. It is either from Revit, or a custom class. Is it one from 'The Building Coder'[^]?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Probably, you need to add a reference to the assembly to your project:
Open the Project branch in the Solution Explorer pane.
Right click "References" and select "Add Reference..." from the menu that appears.
Click the "Browse..." button in the lower right of the dialog that appears and navigate to the DLL file containing the Util class.
Highlight the DLL file, and press "Open".
Click the "Add" button.
Click the "Close" button
You may also need to add a using line to the top of your .CS file to add the namespace to your code.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Datagridview is harder than I anticipated. I would like to click on my column header and select an entire column to change it, or click on my row header and select an entire row to change it, or select multiple cells to change them or a single cell to change it.
Is this possible with the datagridview object? If so, does anyone have a code example? I've been looking over the net and I'm able to get the column selection to work most of the time, but apparently that disables row selection and I would like both of them, depending on which header is clicked?
Thanks for reading.
modified 22-Dec-14 14:56pm.
|
|
|
|
|
|
I think your requirements sound a little ambitious for the DGV, it sounds like you are more after spreadsheet like functionality which you will not get out of a DGV. You might have to look into some of the spreadsheet controls, none of which are free or even cheap.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Is there any way to select a cell and then if the enter key is pressed, have an input box pop up to input a value. Then taking it further, select multiple cells, press the enter key, input box pops up and you can set that same value for all selected cells? Is this possible in the datagridview object?
|
|
|
|
|
If you had followed my earlier suggestion and looked at the properties in the documentation, you would have spotted MultiSelect[^].
|
|
|
|
|
I did follow your suggestion. That doesn't mean it gives a working code example that I can insert into my form and start to figure out its intricacies.
I can't even get the event handlers to work with this object, it tells me the following error for the following code?
Error 4 Cannot implicitly convert type 'System.Windows.Forms.DataGridViewCellEventHandler' to 'System.EventHandler' c:\Form1.cs 51 47
this.dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick); // works
this.dataGridView1.DoubleClick += new DataGridViewCellEventHandler(dataGridView1_CellDoubleClick); // generates the above error
|
|
|
|
|
DataGridView does not have a DoubleClick event, it is inherited from Control. You should be using CellDoubleClick or use the approprite casting for double clicking of the entire form.
|
|
|
|
|
Thank you, celldoubleclick worked.
With multiselect, that appears to just be a property that you enable or disable. If enabled, how can I know which cells I've selected? Then I could input the data for the select cells with a right click command possibly?
|
|
|
|
|
turbosupramk3 wrote: how can I know which cells I've selected? Once again, go and look at the documentation, see what information you get presented with by the different events.
|
|
|
|
|
Hello guys!
How to save text from multiline TextBox2 as (.txt) UTF-16 (Unicode), and not as UTF-8.
This is my code that is not good:
saveFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
saveFileDialog1.FileName = String.Empty;
saveFileDialog1.DefaultExt = ".txt";
DialogResult result = saveFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
byte[] contents;
System.Text.Encoding ascii = Encoding.Unicode;
contents = ascii.GetBytes(textBox2.Text);
using (Stream fs = (Stream)saveFileDialog1.OpenFile())
{
fs.Write(contents, 0, contents.Length);
fs.Close();
MessageBox.Show("File successfully saved!");
}
}
I need a better solution. Thank you!
modified 22-Dec-14 4:22am.
|
|
|
|
|
Member 10410972 wrote: I need a better solution. Better in what way? You need to explain what problem you are trying to solve.
|
|
|
|
|
Thank you.
I really need the code for savefiledialog1 with encoding as:
SaveFileDialog saveFileDialog = new SaveFileDialog();<br />
saveFileDialog.InitialDirectory = "@:\\";<br />
saveFileDialog.Filter =<br />
"ANSI encoding (*.*)|*.*|"<br />
+ "Unicode (UTF-8) encoding (*.*)|*.*|"<br />
+ "Unicode encoding (*.*)|*.*|"<br />
+ "All files (*.*)|*.*";
(My textBob is textBox2.Text)
Please look at the picture:
http://www.dodaj.rs/f/i/9b/orO7WE9/1.png
Please help me! Thank you.
|
|
|
|
|
SaveFileDialog has nothing to do with it, it is just a dialog that gets a filename from the user. You save data to a file by using something like the StreamWriter class[^]. You should read the documentation to find out which options to use for what you want to achieve.
|
|
|
|
|
Doesn't look too bad to me, except for the part about calling your Unicode encoding 'ascii'.
How about using StreamWriter? The constructor takes an encoding and has methods to write strings so you can do away with the byte array stuff.
Regards,
Rob Philpott.
|
|
|
|
|
Hello guys!
This is my code:
private void openToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
OpenFileDialog openFileDialog1 = new OpenFileDialog();<br />
openFileDialog1.Title = "";<br />
openFileDialog1.InitialDirectory = "c:\\";<br />
openFileDialog1.FileName = null;<br />
openFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";<br />
openFileDialog1.FilterIndex = 1;<br />
openFileDialog1.RestoreDirectory = true;<br />
DialogResult result1 = openFileDialog1.ShowDialog();<br />
string file1 = openFileDialog1.FileName;<br />
if (result1 == DialogResult.OK)<br />
{<br />
Encoding enc = Encoding.GetEncoding("Windows-1251 && Windows-1250");<br />
string s = File.ReadAllText(file1, enc);<br />
textBox1.Text = s;<br />
}<br />
<br />
}
The problem with this code:
Encoding enc = Encoding.GetEncoding("Windows-1251 && Windows-1250");
Please see the image:
http://www.dodaj.rs/f/3Z/O6/1uQ1dcT1/33.png
I need the Windows-1250 and Windows-1251. What is the solution? Thank you!
|
|
|
|
|