|
Change
...
dataGridView1.Rows[i].Cells[...
...
to
...
dataGridView1.Rows[dataGridView1.Rows.Count-1].Cells[...
...
Your counter is based on t, which is not equal to the dataGridView.
The signature is in building process.. Please wait...
|
|
|
|
|
two row in my data table it shows only last row
String sql = "select Name,Gender,Course1,Course2 from Info ";
DataTable t = DataAccess.GetDataTable(sql);
for (int i = 0; i <t.Rows.Count; i++)
{
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Column1"].Value =t.Rows[i]["Name"] ;
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Column2"].Value =t.Rows[i]["Gender"] ;
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Column3"].Value =t.Rows[i]["Course1"] ;
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Column4"].Value = t.Rows[i]["Course2"];
}
how i show all the row in gridview plz solve this prob ![Frown | :(](https://www.codeproject.com/script/Forums/Images/smiley_frown.gif)
|
|
|
|
|
This way you end up just filling the same row over and over, also it fails if there is no row in the DataGridView.
I would do it that way instead:
if (dataGridView1.Rows.Count <= i)
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[...
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
thank you Freak30 that means always add dataGridView1.Rows.Add()
|
|
|
|
|
you can also write like this..
//this line write before for loop
//with this line grid(dataGridView1) create line as per dataTable(t)
dataGridView1.RowCount=t.Rows.Count
for (int i = 0; i < t.Rows.Count; i++)
{
dataGridView1.Rows[i].Cells["Column1"].Value = t.Rows[0]["Address"].ToString();
}
|
|
|
|
|
it does not show the multiple it shows only first row ,if i did like
for (int i = 0; i <t.Rows.Count; i++)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells["Column1"].Value = t.Rows[i]["Name"];
dataGridView1.Rows[i].Cells["Column2"].Value = t.Rows[i]["Gender"];
dataGridView1.Rows[i].Cells["Column3"].Value = t.Rows[i]["Course1"];
dataGridView1.Rows[i].Cells["Column4"].Value = t.Rows[i]["Course2"];
}
no prob occur.
|
|
|
|
|
You are using the list t as the source of your index count, rather than dataGridView1 , it should be:
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
dataGridView1.Rows[i].Cells["Column1"].Value = t.Rows[0]["Address"].ToString();
}
(or similar).
Veni, vidi, abiit domum
|
|
|
|
|
is this right ?
String sql = "select Name,Gender,Course1,Course2 from Info ";
DataTable t = DataAccess.GetDataTable(sql);
MessageBox.Show(Convert.ToString(dataGridView1.Rows.Count));
for (int i = 0; i <t.Rows.Count; i++)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells["Column1"].Value = t.Rows[i]["Name"];
dataGridView1.Rows[i].Cells["Column2"].Value = t.Rows[i]["Gender"];
dataGridView1.Rows[i].Cells["Column3"].Value = t.Rows[i]["Course1"];
dataGridView1.Rows[i].Cells["Column4"].Value = t.Rows[i]["Course2"];
}
|
|
|
|
|
Kawshik_itbd wrote: is this right ? It looks like it probably is; what happens when you try it? I would also ask why you are not using databinding to build your view automatically.
Veni, vidi, abiit domum
|
|
|
|
|
it works .how i use databinding? can you gives some example of code ??
|
|
|
|
|
There are lots of samples and articles around that explain databinding and how it can speed up your applications.
Veni, vidi, abiit domum
|
|
|
|
|
the way that i follow is n;t correct or not ??
|
|
|
|
|
Yes, it's correct, in the sense that it does what you need, but databinding is much more powerful and you can do it with a single line of code.
Veni, vidi, abiit domum
|
|
|
|
|
thnaks for advice ![Smile | :)](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
Should be ok, provided you want to append every time you call this function. Else you will probably have to clear the GridControl first.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
can you gives some basics about GridControl?
|
|
|
|
|
you can also write like this..
//this line write before for loop
//with this line grid(dataGridView1) create line as per dataTable(t)
dataGridView1.RowCount=t.Rows.Count
for (int i = 0; i < t.Rows.Count; i++)
{
dataGridView1.Rows[i].Cells["Column1"].Value = t.Rows[0]["Address"].ToString();
}
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using Project1;
namespace Server
{
public partial class Form1 : Form
{
private TcpChannel tcpchannel = null;
private int port = 8998;
private Type type;
private WellKnownObjectMode wellknownobj;
private string objURL;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnKhoi_Click(object sender, EventArgs e)
{
try {
btnTat.PerformClick();
port = Int32.Parse(txtPort.Text);
tcpchannel = new TcpChannel(port);
ChannelServices.RegisterChannel(tcpchannel,false);
type = typeof(Proxy);
objURL ="Prime_URL";
if(rdb_sTon.Checked==true)
wellknownobj = WellKnownObjectMode.Singleton;
else
wellknownobj = WellKnownObjectMode.SingleCall;
RemotingConfiguration.GetRegisteredActivatedServiceTypes(type,objURL,wellknownobj);//Error this line
txtTrThai.Text="Khoi dong server tai Port"+port.ToString()+"luc"+ DateTime.Now.ToString();
}catch(Exception ex){
MessageBox.Show("Loi", ex.Message);
}
}
private void btnTat_Click(object sender, EventArgs e)
{
if (ChannelServices.GetChannel("tcp") != null) {
ChannelServices.UnregisterChannel(tcpchannel);
txtTrThai.Text = "tat server tai port" + port.ToString() + "luc" + DateTime.Now.ToString();
}
}
}
}
|
|
|
|
|
It's telling you that the method doesn't take three parameters. In fact, it doesn't take any parameters - you can find this out by looking up the definition[^] on MSDN. Also, your call here is completely useless because you don't assign it back to anything.
|
|
|
|
|
I am doing a project in which i am trying to read the data that is being sent from my microcontroller to the PC through serial port.
I am ok with the serial part (i guess)...
I was thinking of making it like, first when i run the program a gui would pop up asking user to select the COM port and other details like handshake, parity, baud rate, etc.
And after setting all that when the user presses the START button the current form should close and another form should pop up showing the data being read from the port continously.
Is that possible to create multiple forms ????
If possible please help me in doing so....
|
|
|
|
|
alfie.max15 wrote: Is that possible to create multiple forms
Yes of course it is possible, use winforms or WPF for the UI.
Help you - Ok!
Do some research and decide on a platform, then get a book on that platform, read the book and do the examples.
When you have completed that start your application, when you run across a specific problem come back and we may be able to help you.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanx... I did that...
Now what i specifically want is that when i press the button the form2 should pop up but at the same time the form1 should close.
i tried...
In form1
private void Start_Click (object sender, EventArgs e)
{
secondForm.Show();
this.Close ();
}
but what happened was that the form2 will open and both form 1 and form2 get closed.
i thought only form1 will get close as i had called this from form1
|
|
|
|
|
If Form1 is the main form, the application will end on closing it. You could create 2 additional forms, make the main form invisible and start the second form (for taking the parameters) in the load event of the main form. Also you should open it with ShowDialog() to create a modal form.
On pressing the button confirm you set the DialogResult to something specific, so you get this value as return value from ShowDialog() after closing your parameter form. Then you can open the third form showing the data.
Another approach would be to transfer the logic of opening the second dialog to the program class, opening the second form if the main form was closed using confirm and exit tha pplication only if the second form is closed or the main form is closed in another way than pressing confirm.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
I vote for your "2nd form" becoming the main form. It's what you actually want to see anyway.
The main form can create and show what now is you "1st form". But it essentially is just a dialog to set up some properties. So make it just a dialogue that is started by your main form.
Additional benefit: Later, you can implement a menu, button or whatever control so user can open a connection properties dialogue again, with the same logic you already have (in case user entered wrong parameter, or another controller on another port, or...).
Ciao,
luker
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Text;
namespace ClassLibrary1
{
public class Khachhang:MarshalByRefObject
{
private string tennguoitruoc;
private int songuoi;
public Khachhang (){
tennguoitruoc = "";
songuoi = 0;
Console.WriteLine("Doi tuong duoc khoi tao");
}
public string Laythongtin(string ten){
Console.WriteLine("Doi tuong goi ham");
string thongdiep;
if (tennguoitruoc.Length == 0)
thongdiep = "Chao" + ten + "Ban la nguoi dau tien";
else
"Chao," + ten + ".Co" + songuoi.ToString() +
"nguoitruocban,va" + tennguoitruoc + "la nguoi dung truocban";//Error at this line:tennguoitruoc.
:
songuoi++;
tennguoitruoc = ten;
return thongdiep;
}
}
}
|
|
|
|