6 Replies - 1055 Views - Last Post: 20 November 2012 - 09:29 PM Rate Topic: -----

#1 varanasi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 24-September 12

Regarding size of Winforms

Posted 19 November 2012 - 05:58 AM

Hi,

I have a splitcontainer in a form. 1st panel contains linkedlabels. On clicking the linkedlabel the respective form is opened in the 2nd panel if splitcontainer. But the problem is with the size of form.
If i use Dock = DockStyle.Fill form is displayed in minimized form. I want to fill the form in the panel.

Please help me !

Thank you :)

Is This A Good Question/Topic? 0
  • +

Replies To: Regarding size of Winforms

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9204
  • View blog
  • Posts: 34,581
  • Joined: 12-June 08

Re: Regarding size of Winforms

Posted 19 November 2012 - 09:18 AM

Win forms isn't quite ASP.NET, right? So is this VB.NET or C#?
Was This Post Helpful? 0
  • +
  • -

#3 varanasi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 24-September 12

Re: Regarding size of Winforms

Posted 19 November 2012 - 09:29 PM

View Postmodi123_1, on 19 November 2012 - 09:18 AM, said:

Win forms isn't quite ASP.NET, right? So is this VB.NET or C#?


It is C#. Sorry for not giving complete info.
Was This Post Helpful? 0
  • +
  • -

#4 varanasi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 24-September 12

Re: Regarding size of Winforms

Posted 20 November 2012 - 05:17 AM

View Postvaranasi, on 19 November 2012 - 09:29 PM, said:

View Postmodi123_1, on 19 November 2012 - 09:18 AM, said:

Win forms isn't quite ASP.NET, right? So is this VB.NET or C#?


It is C#. Sorry for not giving complete info.



Heyy I could solve this issue by giving same size as that of panel ie; using

"form.size = new size(splitcontainer1.panel2.width,splitconatiner1.panel.height);"

But now New issue is raised.

In the form that is appearing on the panel after linklabel is clicked, am unable to change the value of checkbox present in datagridview.

To verify if cellcontentclick is working or not i created a messagebox in the event. That messagebox is shown when cell content is clicked but check box value is not changing.

When am executing the form separately its working fine but problem is raised only when its added to the panel of other form.

Even in the other forms that are opened in the panel "gridview.Currentrow.Selected = true" is not working.

Please help me out.

[C# code for form containing Splitcontainer in which forms are opened]

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Department;
using UsersDetails;
using MenuScreen;
using MenuScreen.Properties;
using AccessAllocation;


namespace MenuScreen
{
    public partial class AdminSubMenu : Form
    {
        public AdminSubMenu()
        {
            InitializeComponent();
        }

        private void lilasmdept_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            var dept = new Departmentsandroles{TopLevel=false,Visible=true,Size = new Size(404,456)};
            if(splitContainer1.Panel2.Controls.Count>0)
            {
                splitContainer1.Panel2.Controls[0].Dispose();
            }
            splitContainer1.Panel2.Controls.Add(dept);
        }

        private void lilasmuser_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            var user = new UserDetails { TopLevel = false, Visible = true };
            if (splitContainer1.Panel2.Controls.Count > 0)
            {
                splitContainer1.Panel2.Controls[0].Dispose();
            }
            splitContainer1.Panel2.Controls.Add(user);
        }


        private void lilasmacc_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            var acc = new AccessAllocationForm  { TopLevel = false, Visible = true };
            if (splitContainer1.Panel2.Controls.Count > 0)
            {
                splitContainer1.Panel2.Controls[0].Dispose();
            }
            splitContainer1.Panel2.Controls.Add(acc);
        }
    }
}




code of the form that contains chechkboxgridview
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace AccessAllocation
{
    public partial class AccessAllocationForm : Form
    {
        SqlConnection con = new SqlConnection("Data Source=SPSERVER;Initial Catalog=POS;Integrated Security=True");
        public AccessAllocationForm()
        {
            InitializeComponent();
        }

        private void AccessAllocation_Load(object sender, EventArgs e)
        {
            UpdateRoleAdd();
            UpdateRoleDel();
            gvaaaa.DataSource = GetAccess();
            gvaaaa.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            gvaaaa.Columns[0].HeaderText = "Role ID";
            gvaaaa.Columns[1].HeaderText = "Role";
            gvaaaa.Columns[2].HeaderText = "Sales";
            gvaaaa.Columns[3].HeaderText = "Purchase";
            gvaaaa.Columns[4].HeaderText = "Inventory";
            gvaaaa.Columns[5].HeaderText = "Managment";
            gvaaaa.Columns[6].HeaderText = "Reports";
            gvaaaa.Columns[7].HeaderText = "HR and Admin";

            gvaaaa.CurrentCell.Selected = false;
         
        }

        public DataTable GetAccess()
        {
            DataTable dvaccess = new DataTable();
            //SqlConnection con = new SqlConnection("Data Source=SPSERVER;Initial Catalog=POS;Integrated Security=True");
            try
            {
                con.Open();
                //SqlConnection con = new SqlConnection("Data Source=SPSERVER;Initial Catalog=POS;Integrated Security=True");
                string col = "select * FROM POS_ACCESSALLOTMENT_005";
                SqlCommand cmd = new SqlCommand(col, con);
                dvaccess.Load(cmd.ExecuteReader());
                return dvaccess;
            }

            catch (Exception ex)
            {
                MessageBox.Show("getaccess");
                MessageBox.Show(ex.Message);
                
            }
            
            finally
            {
                con.Close();
            }
            return null;

        }

        public void btnaasave_Click(object sender, EventArgs e)
        {
            UpdateRows();
            gvaaaa.ClearSelection();
           
            
        }

        public void UpdateRoleAdd()
        {
            //SqlConnection con = new SqlConnection("Data Source=SPSERVER;Initial Catalog=POS;Integrated Security=True");
            try
            {

                con.Open();
                string uprole = "INSERT INTO POS_ACCESSALLOTMENT_005 (POS005_ROLE_ID,POS005_ROLE_NAME) select POS003_ROLE_ID,POS003_ROLE_NAME from POS_ROLE_003 WHERE POS_ROLE_003.POS003_ROLE_ID NOT IN(SELECT POS_ACCESSALLOTMENT_005.POS005_ROLE_ID FROM POS_ACCESSALLOTMENT_005) ";
                SqlCommand cmd = new SqlCommand(uprole, con);
                cmd.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message+"roleadd");
            }
            finally
            {
                con.Close();
            }
        }

       
        public void UpdateRows()
        {
            //SqlConnection con = new SqlConnection("Data Source=SPSERVER;Initial Catalog=POS;Integrated Security=True");
            var resultset= 0;
            try
            {
                con.Open();
                foreach (DataGridViewRow row in gvaaaa.Rows)
                {
                    string uprow = "UPDATE POS_ACCESSALLOTMENT_005 SET POS005_SAL='" + row.Cells[2].Value + "',POS005_PUR='" + row.Cells[3].Value + "',POS005_INV='" + row.Cells[4].Value + "',POS005_MGMT='" + row.Cells[5].Value + "',POS005_REP='" + row.Cells[6].Value + "',POS005_HR = '" + row.Cells[7].Value + "' WHERE POS005_ROLE_NAME='" + row.Cells[1].Value.ToString() + "'";
                    SqlCommand cmd = new SqlCommand(uprow, con);
                    resultset = cmd.ExecuteNonQuery();
                    
                    
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message+"updaterows");
            }
            finally
            {
                con.Close();
                if (resultset != 0)
                {
                    MessageBox.Show("Changes saved successfully", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

        public void UpdateRoleDel()
        {
            //SqlConnection con = new SqlConnection("Data Source=SPSERVER;Initial Catalog=POS;Integrated Security=True");
            try
            {
                //SqlConnection con = new SqlConnection("Data Source=SPSERVER;Initial Catalog=POS;Integrated Security=True");
                con.Open();
                string uproled = "delete from POS_ACCESSALLOTMENT_005 where POS005_ROLE_NAME =(select POS005_ROLE_NAME from POS_ACCESSALLOTMENT_005 WHERE POS_ACCESSALLOTMENT_005.POS005_ROLE_NAME NOT IN(SELECT POS_ROLE_003.POS003_ROLE_NAME FROM POS_ROLE_003)) ";
                SqlCommand cmd = new SqlCommand(uproled, con);
                cmd.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message+"roledel");
            }
            finally
            {
                con.Close();
            }
        }

        private void gvaaaa_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        private void gvaaaa_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            this.gvaaaa.CurrentRow.Selected = true;
            MessageBox.Show("cilck");
        }

       
       
    }
}




SQL DATABASE SCHEMA FOR ABOVE CODE:

POS005_ROLE_ID (pk,NCHAR,NOTNULL)
POSOO5_ROLE_NAME (VARCHAR,NULL)
POSOO5_SAL (BIT,NULL)
POSOO5_PUR (BIT,NULL)
POSOO5_INV (BIT,NULL)
POSOO5_MGMT (BIT,NULL)
POSOO5_REP (BIT,NULL)
POSOO5_HR (BIT,NULL)


PLEASE HELP ME SOLVING THIS ISSUE.

This post has been edited by Skydiver: 20 November 2012 - 08:24 AM
Reason for edit:: fixed botched code tag

Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3575
  • View blog
  • Posts: 11,116
  • Joined: 05-May 12

Re: Regarding size of Winforms

Posted 20 November 2012 - 08:41 AM

No directly related to your checkbox issues, but this code is an excellent vector for SQL injection attacks:
                    string uprow = "UPDATE POS_ACCESSALLOTMENT_005 SET POS005_SAL='" + row.Cells[2].Value + "',POS005_PUR='" + row.Cells[3].Value + "',POS005_INV='" + row.Cells[4].Value + "',POS005_MGMT='" + row.Cells[5].Value + "',POS005_REP='" + row.Cells[6].Value + "',POS005_HR = '" + row.Cells[7].Value + "' WHERE POS005_ROLE_NAME='" + row.Cells[1].Value.ToString() + "'";



Posted Image
Was This Post Helpful? 1
  • +
  • -

#6 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4490
  • View blog
  • Posts: 7,822
  • Joined: 08-June 10

Re: Regarding size of Winforms

Posted 20 November 2012 - 09:15 AM

And the solution to the problem Skydiver mentioned:

http://www.dreaminco...ery-a-database/
Was This Post Helpful? 1
  • +
  • -

#7 varanasi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 24-September 12

Re: Regarding size of Winforms

Posted 20 November 2012 - 09:29 PM

View PostSkydiver, on 20 November 2012 - 08:41 AM, said:

No directly related to your checkbox issues, but this code is an excellent vector for SQL injection attacks:
                    string uprow = "UPDATE POS_ACCESSALLOTMENT_005 SET POS005_SAL='" + row.Cells[2].Value + "',POS005_PUR='" + row.Cells[3].Value + "',POS005_INV='" + row.Cells[4].Value + "',POS005_MGMT='" + row.Cells[5].Value + "',POS005_REP='" + row.Cells[6].Value + "',POS005_HR = '" + row.Cells[7].Value + "' WHERE POS005_ROLE_NAME='" + row.Cells[1].Value.ToString() + "'";



Posted Image


Thank you for the suggestion. I ll surely take it and change to parameterized query from the solution given by Curtis Rutland

View PostCurtis Rutland, on 20 November 2012 - 09:15 AM, said:

And the solution to the problem Skydiver mentioned:

http://www.dreaminco...ery-a-database/


Thank you for giving me a good solution. :bigsmile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1