|
Still the online test/quiz?
Place your radio buttons and text boxes on the form as you would usually do. Set the textboxes' Visible property to false.
When you reach the 32nd question, set the radio buttons' Visible property to true and the textboxes' Visible property to true.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
hi all,
i have a list view and lisviewitems in this listview , now when i right click on any lisviewitem it getting selected , i don't want to select it with right click , i just want to select itwith left click.How can i cancel the event when it's right click coz there is no cancel in MouseEventArgs.
please help me.
thanx.
Praveen Sharma
|
|
|
|
|
in my C# program,i input "at" in a textBox,then the program send "at" to serialport,but when i click receive button,the message I receive from serial port is the same as what I input,namely "at",not "ok",why?who can answer my question?How I solve this problem and get the right response "ok" from serial port?
next is my code:
public partial class Form1 : Form
{
private SerialPort sp = null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
sp = new SerialPort("COM1");
sp.ReadTimeout = 5000;
sp.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
sp.Write(textBox1.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button3_Click(object sender, EventArgs e)
{
try
{
/*string text=null;
char[] buffer = new char[10];
sp.Read(buffer,0,6);
for (int i = 0; i < buffer.Length; i++)
{
text += buffer[i];
}
textBox2.Text = text;*/
/*string text = null;
char t = (char)sp.ReadChar();
text+=t.ToString();
while (true)
{
t = (char)sp.ReadChar();
if (t == '\0') break;
else text += t.ToString();
}
textBox2.Text = text;*/
string text = null;
byte[] t = new byte[20];
char[] c = new char[20];
sp.Read(t, 0, t.Length);
sp.Read(t, 0, t.Length);
c = Encoding.ASCII.GetChars(t);
int i;
for (i = 0; i < c.Length; i++)
{
if (c[i] == 'O' || c[i] == 'K')
text += c[i].ToString();
}
textBox2.Text = text;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
|
|
|
|
|
|
if the end result is not what you want it is wise to look at the intermediate data,
in your case log the bytes that the serial port returns to you (I would use HEX numbers).
If they are exactly what you have sent, then either your target device is echoing them,
or you have an unintended connection between TxD and RxD (transmit data and receive data)
on your serial cable.
|
|
|
|
|
Hello,
how can i display the hex values for each byte of a sting in a richtextbox?
thanks!
|
|
|
|
|
Hello,
roiter wrote: for each byte of a sting
I don't understand this!
But maybe you are searching for this:
string HexText= String.Format("{0:X}", value);
Hope it helps!
All the best,
Martin
|
|
|
|
|
thank you! i will try it later.
I am knew in C#. in C there is no datatype string, you can define a byte array and use it as a string. So each byte is manipulateable by indexing.
|
|
|
|
|
Wellcome
All the best,
Martin
|
|
|
|
|
roiter wrote: use it as a string. So each byte is manipulateable by indexing
in C# the indexer (myString[x]) returns the 16-bit character at position x.
|
|
|
|
|
In .NET the characters are not bytes, they are unicode characters. A string is basically an array of char . A char is a 16 bit value, so you can cast it to a short or an int to get the character code.
Example:
foreach (char c in someString) {
int code = (int)c;
Console.Write(code.ToString("x4"));
Console.Write(" ");
}
---
single minded; short sighted; long gone;
|
|
|
|
|
Hello EveryBody,
I had two combo box (combo box1, combo box2)
I had populated the combox1 using dataset (having values in display member and value member)
I want to pupulate combo box2 on the selectedindexChangeEvent but
I am getting System.Data.DataRowView on comboBox1.selectedvalue.tostring();
I am unable to understand why it is returning this value.
And outside this event it is giving right value.
working on c# (windows application)
Regards,
rahul saini
|
|
|
|
|
It would be more helpful if you could put some code also...
Just call me Valy...
|
|
|
|
|
Hi Valy,
Here is the code for populating the combo box1
string sqlQuery = "select * from category ";
SqlConnection objConnection = new SqlConnection(objFunctions.strConn);
objConnection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(sqlQuery, objConnection);
DataSet ds = new DataSet();
adapter.Fill(ds);
DataTable objDataTable = ds.Tables[0];
cmb_category.DataSource = objDataTable;
cmb_category.DisplayMember = "categoryName";
cmb_category.ValueMember = "categoryId";
objConnection.Close();
AND on selectedIndexChangeEvent
I m populating combo box using comboBox1.selectedValue
but it is returning System.Data.DataRowView
Regards,
rahul saini
|
|
|
|
|
hi
instead of using combobox1.selectedvalue
you have to use
combobox1.selectedindex.tostring()
Nisar Inamdar.
|
|
|
|
|
Hi Nisar,
It is giving the index value but i want the selectedItemValue for populating
comboBox2 with help of the value i had to retrieve value from database
Regards,
rahul saini
|
|
|
|
|
Hi Rahul,
on combo1.selectedIndexEvent use query
" Select fieldName from tablname where fieldname="+combo1.Selectedindex.toString()";
Nisar Inamdar.
|
|
|
|
|
Yes I using the same query but
as on populating comboBox1 i get
category1 its value is 23
category2 its value is 32
but when on selecting category1 its index value is 0 and that is wat comboBox1.selectIndex is giving and i want its value that is 23.
Regards,
rahul saini
|
|
|
|
|
hi rahul,
Try combo1.SelectedItem.ToString();
It will be worked.
Nisar Inamdar.
|
|
|
|
|
I think I got it.
You must use ((DataRowView)comboBox1.SelectedItem).Row["categoryId"].ToString() instead of comboBox1.selectedValue
Just call me Valy...
|
|
|
|
|
Hi Valy ,
Thanks,
Its working fine.
Regards,
rahul saini
|
|
|
|
|
My code looks like this:
List<string> items;
private void button2_Click(object sender, EventArgs e)
{
//finalize button click
items = new List<string>();
for (int i = 0; i < passagelistBox.Items.Count; i++)
{
items.Add(passagelistBox.Items[i].ToString());
}
foreach (string currentitem in items)
{
DoInsertData(currentitem.Split(new char[] {','}));
}
}
private void DoInsertData(string[] item)
{
string sql = "INSERT INTO tblPassages (column_num, row_num) VALUES (@p1, @p2)";
cmd.CommandText = sql;
SqlParameter p1 = new SqlParameter("@p1", item[0]);
SqlParameter p2 = new SqlParameter("@p2", item[1]);
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
p1.SqlDbType = SqlDbType.VarChar;
p2.SqlDbType = SqlDbType.VarChar;
cmd.Connection = cn;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
cmd.Connection = null;
}
while I wxecute this code at the line : cmd.ExecuteNonQuery(); a exception is raised as follws:
System.Data.SqlClient.SqlException was unhandled
Message="String or binary data would be truncated.\r\nThe statement has been terminated."
Source=".Net SqlClient Data Provider"
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=8152
Procedure=""
Server="localhost"
State=2
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at SeatLayout.Form1.DoInsertData(String[] item) in D:\Box Office\SeatLayout\SeatLayout\Form1.cs:line 179
at SeatLayout.Form1.button2_Click(Object sender, EventArgs e) in D:\Box Office\SeatLayout\SeatLayout\Form1.cs:line 161
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at SeatLayout.Program.Main() in D:\Box Office\SeatLayout\SeatLayout\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Please help me.....
Thanks in advance..
Regards
Sangram
|
|
|
|
|
why do you use those two parameters @p1 and @p2 when you can simply do something like this:
string sql = "INSERT INTO tblPassages (column_num, row_num) VALUES ('" + item[0] + "','" + item[1] + "')";
I presume that column_num and row_num are string values in the database.
Usually you use parameters when you use a stored procedure to execute a query.
So you don't need these lines
SqlParameter p1 = new SqlParameter("@p1", item[0]);
SqlParameter p2 = new SqlParameter("@p2", item[1]);
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
p1.SqlDbType = SqlDbType.VarChar;
p2.SqlDbType = SqlDbType.VarChar;
Tell me if it helped...
Just call me Valy...
|
|
|
|
|
Hi Valy,
I changed the code as you said but the exception is same.
Regards
Sangram
|
|
|
|
|
|