hi,
I have a form in which there is a datagridview. In that I will populate the dgv from the database.Now in that dgv if I right click a particular row there should appear a small pop-up window, which is similar when we right click on a empty window which shows various options like arrange icons by,refresh, cut, copy, paste, properties, etc.
Vimal KandasamyPosted Apr 29, 2009, 5:27 AM
Change your button click event content as
{{{MessageBox.Show("Not Found");sachi vasishtaPosted Apr 29, 2009, 4:23 AM
vimal I tried your code but If i give a name which is not in the datagridview then it is giving error saying NullReferenceException was unhandled
vimal this is the code I have written for the button click event
private void button1_Click_2(object sender, EventArgs e){
string uname = textBox1.Text; for (int i = 0; i < dataGridView1.Rows.Count; i++){
if ((dataGridView1.Rows[i].Cells[1].Value.ToString() == uname) && (i < dataGridView1.Rows.Count)){
dataGridView1.Rows[i].DefaultCellStyle.BackColor =
Color.Red;dataGridView1.Rows[i].DefaultCellStyle.ForeColor =
Color.Black; break;}
else if ((dataGridView1.Rows[i].Cells[1].Value.ToString() != uname) && (i < dataGridView1.Rows.Count)){
continue;}
else{
MessageBox.Show("notfound"); break;}
}
}
and here is the written to populate dgv
private
void Form1_Load(object sender, EventArgs e){
OdbcConnection ocon =
new OdbcConnection("Dsn=testsample");ocon.Open();
OdbcCommand ocom =
new OdbcCommand();ocom.Connection = ocon;
ocom.CommandText =
string.Format("select * from samples");DataTable dt =
new DataTable();OdbcDataAdapter adap =
new OdbcDataAdapter(ocom);adap.Fill(dt);
dataGridView1.DataSource = dt;
ocon.Close();
}
Vimal KandasamyPosted Apr 29, 2009, 1:25 AM
Simply get user id from user and retrieve data from database using select query something like
select * from table where userid=textbox1.text.
If it returns a value then it available in db and if it return empty data set then show your error msg.
after get value from db.
then find its row by searching using for loop
something like below.
{{//here userid is value retrieved from database//i assumed that cell[1] refers userid.
try this
sachi vasishtaPosted Apr 29, 2009, 12:53 AM
thanks vimal.
vimal in a form containing dgv I have some data populated from the db and in the same form i have 3 textboxes namely firstname, lastname , and userid and a button called search.When I enter data into these 3 textboxes or two textboxes and click a search button then if it is a successfull search(if it matches with the data stored in the db)then a row in the dgv which matches with the values in textboxes should blink or should become bright(just to indicate the user that the required row is found) , if not present then it should display some unsuccessful msg.
Vimal KandasamyPosted Apr 29, 2009, 12:18 AM
use contextMenuStrip to achive this.
add contextMenuStrip control in your form and add menus in that like cut,copy paste and write coding for menu items.
after that set datagridview's ContextMenuStrip as contextmenustrip1.
then whenever your right click on dgv,it will show that menu.
try this
StefanPosted Apr 28, 2009, 12:18 PM
Create the form that you want to show up. Then use one of these event handlers to show the form: "CellClick", "CellContentClick", "CellContentDoubleClick", "CellDoubleClick". Or, you could use "CellMouseEnter" to show the form whenever the user moves the mouse over a cell. For specific rows you can use the "RowHeaderMouseClick".
Hope this helps!