Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all 2535 articles
Browse latest View live

how to add an internal DB on a project

$
0
0

Hello all.. newbie here!!

can someone explain me the best way (or just the easy) to add to a windows form project (VB) with 3 or 4 forms a local database (loaded from and to a XML file) with 5 tables (related)  of information? don't think SQL is necessary, this will be a small project.

My main issue is how to define the database on the Visual Studio Community 2015 in order to be able to do something like <databaseobject>.loadxml(file) and <databaseobject>.<tablename>(6) = <value>. I was able to do something like this, but when changing forms, the values inserted on the database tables were lost :(

For now, the more I search for something simillar, the more confused I get. Please give me some pointers using keywords that searching for them will give me more info on each step. Don't need to elaborate too much and spent too much time with me.

Thank you very much for your time.


.Net Windows forms ComboBox Accessibility Issue

$
0
0

Hi ,

We are using .net winforms application(C#). 

Screen reader(NVDA) is unable to read combobox items in the below scenario.

Scenatio 1 : Focus to the combobox and use Alt+Up/Down keys->Combobox items open -> current selected item is Item 2-> enter Esc/Enter key-> item2 was selected in combobox

Then use UP/Down keys->Items are changing from combox box but screen reader is not reading.

ComboBox Properties -> DropDownStyle = ComboBoxStyle.DropDownList

Scenario 2 : Change the DropDownStyle =ComboBoxStyle.DropDown then its reading properly but some small issues are observed.

1) Initial selection its reading like 

[combo box  collapsed
edit
selected Item 1]

we don't want edit.

This is because combobox in edit mode.

Can you please suggest the solution?

Disabling SetSelectedRowCore without infinite loop

$
0
0

When I set CurrentCell it has the side effect of changing the selected rows as well.  This is probably because I set            

SelectionMode                              = DataGridViewSelectionMode.FullRowSelect;

I would like to disable this behavior and simply set the CurrentCell without changing the selected rows.  I tried overriding the code to set the selected rows as follows

        protected override void SetSelectedRowCore(int rowIndex, bool selected) {
           if (filtered) return;

            base.SetSelectedRowCore(rowIndex, selected);
        }

However, I end up in an infinite loop until I actuall call the base.SetSelectedRow(),  Is there any way to set the CurrentCell without affecting the Selected property?

Thank you,

Nathan

ContextMenuStrip in DataGridView - get the current column

$
0
0

Hi!

I try to implement an interactive filter to my DataGridView. So I've created a ContextMenuStrip with to menus "Add Filter" and "Remove Filter". I've assigned this ContextMenuStrip to each HeaderCell of each coulmn. So that the ContextMenuStrip is only shown on the header.

What I now need is at the opening of the ContextMenuStrip on which Column the ContextMenuStrip is displayed. How can I do this?

I've tried the following but this code returns the last active column:

ContextMenuStrip

myMenu = (ContextMenuStrip)((ToolStripMenuItem)sender).GetCurrentParent();
DataGridView gdvFilter = (DataGridView)myMenu.SourceControl;
gdvFilter.CurrentCell.ColumnIndex

Thanks in advance...
Greets Markus

Visual Studio Deleting Databound DGV

$
0
0
I'm not sure what the hell keeps happening and it's driving me up the wall.  I added the DGV to the form and ran the program, all was well.  Then I closed it and my form errored out saying the grid didn't exist.  It's done this 4x in a row now, the designer.cs file has all the previous grids, but WTF keeps happening?  The data connection/feed works, as evidenced by the rest of the form, but for some reason it will not let me keep my grid.

May the fleas of a thousand camels feast happily on the lower regions of your enemies. And may their arms be too short to scratch!

Bind Report to Datagrid View... HOW?

$
0
0

how can i bind my report/report Viewer to a datagrid view?

ive created an ID card design in a Report. I bind all textbox in the report in my database fields(Data set). but when i run the program, the reportViewer only displays the data from the first rowof my database.

Now, I want to bind my report to a datagrid so i can control which row i am going to display in the reportViewer.

Sorry for my ignorance...im just a college freshmen

C# Access/OLEDB Database Application Keeps Crashing

$
0
0

I'm at a bit of a loss.  I've got a MS Server development environment with VS 2010.  When I run the application file on that, everything loads and works.  I switch it over to my regular Windows 7 desktop and it stops.  What's odd about this, I used the wizard to add the dataset.  I changed the generated connection string slightly to look at the startup folder. 

@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb"

I've got a manually coded connection string for a different form (the one that keeps crashing).  When I set the readout, both are identical.  But when I try to load the form that uses the manual string it gives me the "stopped working" error every single time.  Adding to the frustration, I set a string to record a field from the database and it does in fact load the data, so apparently the form itself keeps crashing.  I've checked and I do have the drivers for .NET and Access on both environments.  I'm not sure what to do right now.  Can anyone point me to what exceptions to throw and where/when to diagnose this?  Or is it possible I'm lucky enough that I might just be missing a driver I don't know about?  Ask anything and I'll answer, I'm not sure what info would help.

Immediate details that may be relevant

.NET 4.0 application written in C#

Access .mdb database

My function to load the data in the data access class, and all three lines of the popup are identical.  It shows that, shows me the table data, then quits.  But never on the dev computer.  I copied the .exe and database to a new folder and ran it stand-alone, the development environment works, the windows 7 does not.

  public void fill_Table()
        {
            string folder = Convert.ToString(Path.Combine(Application.StartupPath, "database.mdb"));
            this.connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb");
            table.Clear();
            OleDbDataAdapter da = new OleDbDataAdapter("Select * FROM table", connection);
            da.Fill(table);
            //MessageBox.Show(this.connection.ConnectionString.ToString() + '\n' + Properties.Settings.Default.myConnectionString + '\n' + folder);
            
        }


May the fleas of a thousand camels feast happily on the lower regions of your enemies. And may their arms be too short to scratch!

Login with auth can't read if admin or not.

$
0
0

Hi; I am trying to check if someone is admin or not with a simple login form, my login works but when i try to check if admin or not that if statement doesn't work. I have a table with 3 column with username, password and type. I want to check if in the type column it writes Admin or not. Here is my code:

private void button1_Click ( object sender , EventArgs e )
                {
                    SqlConnection baglanti = new SqlConnection ( @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Mehmet\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Database1.mdf;Integrated Security=True;User Instance=True;" );
                    SqlDataAdapter adabtor = new SqlDataAdapter ( "select Type from Log_In where Username='" + UserNametextBox1.Text + "' and Password = '" + PasswordtextBox2.Text + "'",baglanti);
                    DataTable tablo = new DataTable();
                    adabtor.Fill(tablo);
                    if ( tablo.Rows.Count == 1 )
                        {
                        logInToolStripMenuItem.Enabled = false;
                        logOutToolStripMenuItem.Enabled = true;
                        LogInpanel1.Visible = false;
                        Aboutpanel2.Visible = true;
                        //MessageBox.Show ( tablo.Rows [ 0 ] [ 0 ].ToString () ); i use this to see what returns from this code, and code returns the correct value like Admin in this case, i also tryed to change Admin to 1, nothing changed
                        if ( tablo.Rows [ 0 ] [ 0 ].ToString () == "Admin" )
                            {
                            addAUserToolStripMenuItem.Visible = true;
                            MessageBox.Show ( "haydi" );
                            }
                        }
                    else
                        MessageBox.Show ( "Username or Password is wrong." );
                }




Override OnEnter to disable formatting onenter text but breaks Data Binding

$
0
0
public class CustomTextBox
{

    protected override void OnEnter(EventArgs e)
    {

        if (this.DataBindings.Count > 0)
        {
            this.cancelvalidating = true;
            this.DataBindings[0].FormattingEnabled = false;
            this.cancelvalidating = false;
        }

        OldText = this.Text;
        base.OnEnter(e);
    }

    protected override void OnLeave(EventArgs e)
    {
        if (this.DataBindings.Count > 0)
        {
            this.cancelvalidating = true;
            this.DataBindings[0].FormattingEnabled = true;
            this.cancelvalidating = false;
        }
        base.OnLeave(e);
    }


}
when you enter the binded textbox format should disappear and onleave should the text again formatted. when I try this code databinding breaks

How to prevent currently loged in user from deleting himself from database?

$
0
0

Hi;

I have a data table contains username and password and type, and a gridview to edit users. Now when I click the delete user button I want it to check if the current user name and selected rows user name is same or not. I have a string called kullaniciadi where I keep last loged in username from textbox1.text like this:

kullaniciadi = UserNametextBox1.Text;

And I tryed this but well it doesn't work for apearently obvious reasons couse I couldn't find anything on the internet about this:

if ( log_InDataGridView.CurrentCell.Value.ToString == kullaniciadi)
                    MessageBox.Show ( "Cannot delete currently loged in user" );
How can I do this?
Thanx.

GENERAL ELECTRIC (repair) صيانة جنرال اليكتريك 0235682820 ، توكيل جنرال اليكتريك 01210999852

$
0
0

الرائدون فى مجال صيانة الاجهزة المنزلية , مصرتوفر شركة صيانة جنرال اليكتريك  الصيانة والتجديد للاجهزة ارقام اتصال جنرال اليكتريك  0235682820 01096922100|01210999852-المحمول :01060037840 غسالات جنرال اليكتريك  ,غسالة جنرال اليكتريك  , ثلاجات جنرال اليكتريك  , ثلاجة جنرال اليكتريك  ,دراير جنرال اليكتريك  ,مجفف جنرال اليكتريك  ,لاندرى جنرال اليكتريك  ,ايس ميكر جنرال اليكتريك  , general electricغسالة general electric ثلاجات general electricديب فريزر general electric غسالات ملابس general electric غسالات اطباقمركز صيانة جنرال اليكتريك  يغطى مناطق ( القاهرة الكبرى ) للاصلاح بالمنزلتعد واحدة من اكبر شركات الصيانة فى مصر ( صيانة جنرال اليكتريك  الاولى فى مصر ) نحن نعتمد على تصليح جنرال اليكتريك  الاجهزة المنزلية الاولة فى مصرمجموعة شركات جنرال اليكتريك  احدى الشركات الرائدة فى مجال ( صيانة غسالات جنرال اليكتريك  &صيانة ثلاجات جنرال اليكتريك  &صيانة ديب فريزر جنرال اليكتريك  & صيانة مجفف جنرال اليكتريك  & صيانة لاندرى جنرال اليكتريك  &صيانة غسالات اطباق جنرال اليكتريك  & صيانة غسالات ملابس جنرال اليكتريك  ، صيانة غسالات صحون جنرال اليكتريك  &صيانة ايس ميكر جنرال اليكتريك ) الصيانة تشمل الجهاز بالكامل (( الصيانة الشاملة)) general electric maintenance ,repair general electric

0235699066 || 01093055835 || 01129347771 || 0235710008

وكيل جنرال اليكتريك حدائق الهرم ,توكيل جنرال اليكتريك  الرماية , توكيل جنرال اليكتريك الجيزة الجديدة

اصلاح غسالات جنرال اليكتريك  , مراكز صيانة جنرال اليكتريك  , اصلاح وصيانة جنرال اليكتريك  , توكيل صيانة جنرال اليكتريك  ,الوكيل صيانة جنرال اليكتريك  , وكيل جنرال اليكتريك  ,خدمة جنرال اليكتريك  ,ارقام جنرال اليكتريك  , اقرب جنرال اليكتريك  , اصلاح جنرال اليكتريك  ,افضل صيانة جنرال اليكتريك  ,اجود صيانة جنرال اليكتريك  ,الاول جنرال اليكتريك  , المتقدم جنرال اليكتريك  ,ارشادات صيانة جنرال اليكتريك ,وكلاء صيانة جنرال اليكتريك  ,الوكلاء جنرال اليكتريك  ,الوكالة جنرال اليكتريك  ,خدمة اصلاح غسالات جنرال اليكتريك  ,الرئيسى جنرال اليكتريك  ,اعمال صيانة جنرال اليكتريك  ,تعد خدمة الدعم الفنى من احدث خدمات شركة جنرال اليكتريك  general electricagent وكيل جنرال اليكتريك  اسرع تحقيق الصيانة الجيدة جنرال اليكتريك  &افضل ارشادات صيانة جنرال اليكتريك  &نقوم بتقديم خدمة الصيانة الفورية جنرال اليكتريك  &الجودة هى العنصر الاساسى فى صيانة جنرال اليكتريك  الجيزة & General electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electric general electricتتعهد مجموعة شركات ( صيانة جنرال اليكتريك  ) بتقديم اجود خدمة وتقديم اعلى مستوى من التدريب اعلى كفائة صيانة جنرال اليكتريك  ( مركز صيانة جنرال اليكتريك  ) GENERAL ELECTRICحيث اننا المركز الوحيد فى مصر { صيانة جنرال اليكتريك  } مع تحيات ادارة توكيل صيانة جنرال اليكتريك

توكيل جنرال اليكتريك ,صيانة جنرال اليكتريك  ,مركز صيانة جنرال اليكتريك ,صيانة ثلاجات جنرال اليكتريك  ,توكيل جنرال اليكتريك فى مصر , توكيل جنرال اليكتريك  الوكيل الرسمى ,ثلاجات جنرال اليكتريك , صيانة غسالات جنرال اليكتريك   ,جنرال اليكتريك مصر , غسالات جنرال اليكتريك  , ثلاجات جنرال اليكتريك , شركة جنرال اليكتريك  , غسالة جنرال اليكتريك , فريزر جنرال اليكتريك  ,لاندرى جنرال اليكتريك ,مجففات جنرال اليكتريك  , اصلاح دراير جنرال اليكتريك , اصلاح غسالات اطباق جنرال اليكتريك  , الصيانة جنرال اليكتريك ,خدمة اصلاح جنرال اليكتريك , جودة خدمة جنرال اليكتريك  ,دليل اصلاح جنرال اليكتريك ,خدمة جنرال اليكتريك  السريعة , اصلاح جنرال اليكتريك القياسى,مركز اصلاح جنرال اليكتريك  ,جنرال اليكتريك صيانة موجهه,تصليح اجهزة جنرال اليكتريك  ,صيانة منتجات جنرال اليكتريك ,ضمان صيانة جنرال اليكتريك  ,خلية صيانة جنرال اليكتريك ,اعمال صيانة جنرال اليكتريك  ,اصلاح وتشغيل جنرال اليكتريك ,صيانة لوحة المتاح جنرال اليكتريك  ,اصلاح اعطال جنرال اليكتريك ,تعليمات صيانة جنرال اليكتريك  ,ضمان صيانة جنرال اليكتريك ,اصلاح اجهزة جنرال اليكتريك  ,

0235699066||01112124913||0235710008 ||01060037840 || 01207619993

Datagridview master check-box in c# windows application

$
0
0

Hi ,

I have a datagridview which is having 1st column as check-box column and header having master check-box which select/un-select all checkboxs.

We are supporting the CATO(Accessibility). I need to navigate master check box through TAB key. I can able to select using mouse.

Can you please propose a solution?

Operation did not succeed because the program cannot commit or quit a cell value change.

$
0
0

Hello everyone,

I got the following error message :

"Operation did not succeed because the program cannot commit or quit a cell value change."

When I sets the current cell to anyone cell of DataGridView.

I have also override one method for that named
SetCurrentCellAddressCore(). But still error remains......


protected override bool SetCurrentCellAddressCore(int columnIndex, int rowIndex, bool setAnchorCellAddress, bool validateCurrentCell, bool throughMouseClick)
                {

                    try
                    {                       
                        return base.SetCurrentCellAddressCore(columnIndex, rowIndex, setAnchorCellAddress, validateCurrentCell, throughMouseClick);                      
                   
                    }
                   
                }

And other problem is that after this error, two or three blank rows added automatically in datagridview....

If anybody have the solution please reply.....

How to perform databinding with WinForms and Entity-Framework 6

$
0
0
I'm competent with ASP.NET programming, both web forms and MVC, but just coming up to speed with WinForms. 

I assumed that I could find a walk-through/demo/tutorial on databinding WinForm controls with Entity Framework 6. 

What I've found, though, is that there are plenty of tutorials about winform databinding in general, a few on databinding to EntityFramework 4.X, but no tutorials on WinForm databinding with EF 6.

Can somebody point me to a WinForm databinding to EF6 tutorial? If not, can you provide a 1000-foot overview? 

Ideally, it would also include the use of the DataGridView control and Master/Detail, Master/List scenarios.

DataGridView Col mul

$
0
0

hello Sir i am creating a POS and i want to multiply two columns in gridview and show result in it how can i do it?


Binding DataGridView to Junction (many-to-many) table.

$
0
0
Public Class InterviewForm
    'Public drPoCo As JobHuntingDataSet.PositionCompanyRow
    'Public drP As JobHuntingDataSet.PositionRow
    'Public drC As JobHuntingDataSet.CompanyRow

    Private Sub InterviewForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If Not blnPoCoBound Then
            companyComboBox.DataBindings.Clear()
            companyComboBox.DataBindings.Add("Text", JobHuntingForm.PositionCompanyBindingSource, "CompanyID")
            positionComboBox.DataBindings.Clear()
            positionComboBox.DataBindings.Add("Text", JobHuntingForm.PositionCompanyBindingSource, "PositionID")
            InterviewDateDateTimePicker.DataBindings.Clear()
            InterviewDateDateTimePicker.DataBindings.Add("Text", JobHuntingForm.PositionCompanyBindingSource, "InterviewDate")

            companyComboBox.DataSource = JobHuntingForm.JobHuntingDataSet.Company
            companyComboBox.DisplayMember = "Name"
            companyComboBox.ValueMember = "CompanyID"

            positionComboBox.DataSource = JobHuntingForm.JobHuntingDataSet.Position
            positionComboBox.DisplayMember = "Title"
            positionComboBox.ValueMember = "positionID"
        End If
    End Sub

    Private Sub EmployeeForm_Activated(sender As Object, e As EventArgs) Handles Me.Activated
        If Me.Tag.Equals("Add") Then
            JobHuntingForm.PositionCompanyBindingSource.AddNew()
            companyComboBox.Text = "--Choose a Company--"
            positionComboBox.Text = "--Choose a Position--"
            InterviewDateDateTimePicker.Visible = False
            Me.Text = "Add Interview Information"
            saveButton.Text = "Save New Interview Setup"
            intcancelButton.Text = "Cancel Setup"
        ElseIf Me.Tag.Equals("Edit") Then
            Me.Text = "Edit Interview Details"
            saveButton.Text = "Save Changes"
            intcancelButton.Text = "Cancel Changes"
            'companyComboBox.Text = drC.Name.ToString
            'positionComboBox.Text = drP.Title.ToString
        End If
        'drPoCo = JobHuntingForm.PositionCompanyBindingSource.Current.row
    End Sub

    Private Sub saveButton_Click(sender As Object, e As EventArgs) Handles saveButton.Click
        If companyComboBox.SelectedIndex = -1 OrElse positionComboBox.SelectedIndex = -1 Then
            JobHuntingForm.PositionCompanyBindingSource.CancelEdit()
            MessageBox.Show("No Company Name or Position Title was selected", "No record was added", MessageBoxButtons.OK,
                MessageBoxIcon.Information)
            Exit Sub
        ElseIf InterviewDateDateTimePicker.value < Date.Today Then
            JobHuntingForm.PositionCompanyBindingSource.CancelEdit()
            Exit Sub
            MessageBox.Show("You chose a date before today, No record was saved")
        ElseIf InterviewDateDateTimePicker.Value = Nothing Then
            InterviewDateDateTimePicker.Value = "No Interview date was set"
            JobHuntingForm.PositionCompanyBindingSource.EndEdit()
            JobHuntingForm.PositionCompanyTableAdapter.Update(JobHuntingForm.JobHuntingDataSet.PositionCompany)
            Me.Hide()
        Else
            JobHuntingForm.PositionCompanyBindingSource.EndEdit()
            JobHuntingForm.PositionCompanyTableAdapter.Update(JobHuntingForm.JobHuntingDataSet.PositionCompany)
            Me.Hide()
        End If
    End Sub
    Private Sub Cancelbutton_Click(sender As Object, e As EventArgs) Handles intcancelButton.Click, Me.FormClosing
        JobHuntingForm.PositionCompanyBindingSource.CancelEdit()
        Me.Hide()
    End Sub

    Private Sub yesRadioButton_CheckedChanged(sender As Object, e As EventArgs) Handles yesRadioButton.CheckedChanged, noRadioButton.CheckedChanged
        If noRadioButton.Checked = True Then
            InterviewDateDateTimePicker.Visible = False
        ElseIf yesRadioButton.Checked = True Then
            InterviewDateDateTimePicker.Visible = True
        End If
    End Sub
End Class
My comboboxes go blank after I make a selection and a null value is entered

BindingSource.DataSource Problem

$
0
0

I've been struggling with a problem for days.

I always try to let Visual Studio take care of the binding by dragging and dropping tables on to a form. Then Fill() does the rest.

this.tblTriCntrsTableAdapter.Fill(this.processDataSet.tblTriCntrs);

I added a line in Fill in the commandText DataSet.xsd file by adding  WHERE (InActive = 'false')

The binding source is automatically created.

In this case I needed two binding sources where the DataMember = tblTriCntrs and the DataSource = processDataSet.

So I renamed the original and created a second just like the original. Except they have different names and filters.

tblTriCntrs1BindingSource.Filter = "TricanterNum = 1";
tblTriCntrs2BindingSource.Filter = "TricanterNum = 2";

There is never more than one record with "Inactive = false" for each binding source. And sometimes just one or neither have a record where "Inactive =false"

This all works well everywhere in a fairly substantial program.

Except where I need to let the user scroll through closed / "Inactive = true" records.

So I create a temporary table "tblREVIEW1" to load just one record at a time where "Inactive = true" and this works well for viewing the closed records.

I change the Data Source like this: tblTriCntrs1BindingSource.DataSource = tblREVIEW1;

When the user is done scrolling I reset the Data Source back the way it was like this:tblTriCntrs1BindingSource.DataSource = this.processDataSet.tblTriCntrs;

This is where I'm having problems.

For some reason the above filters are no longer working after changing the data source back to the way it was.

DataRowView drv1 = (DataRowView)tblTriCntrs1BindingSource.List[0];
DataRowView drv2 = (DataRowView)tblTriCntrs2BindingSource.List[0];

Both drv1 and drv2 point to the same record even though drv1's filter should make it not point to any records because there is no  "TricanterNum = 1" WHERE (InActive = 'false') They all = 'true'

I tried Load() again and resetting the filters after the load but nothing works.

Sorry for all this. I just hope this make sense and someone can help me get the binding sources back on track.

Thank you.


Cannot save tables in VisualStudio 2015

$
0
0

In Visual Studio 2015 I create a new Service Based Database.  I add a table to the database and make edits to the table.  I Save All changes and the table is never saved into the database.

Any thought would be appreciated

Thank you in advance

Brandon

How to update changed row color on DataGridView (in tabs)

$
0
0

I have a number of tabs with with a DataGridView on each. When I change the row color on some of the GridViews the change doesn't take place until I click the last tab. Then going back to the other tabs, first then, I can see that the row colour has changed.

What do I need to update in order for the change to take place, without the need to click the last tab?

//Read Data from the First Sheet. using (OleDbConnection con = new OleDbConnection(conStr)) { using (OleDbCommand cmd = new OleDbCommand()) { using (OleDbDataAdapter oda = new OleDbDataAdapter()) { int pageNumber = 0; for (int i = 0; i < stringArray.Length; i++) { DataTable dt = new DataTable(); cmd.CommandText = "SELECT * From [" + stringArray[i] + "]"; cmd.Connection = con; con.Open(); oda.SelectCommand = cmd; oda.Fill(dt); con.Close(); //Populate DataGridView. /* Dynamic DataGridView */ dgwDynamic = new DataGridView(); dgwDynamic.Name = "DataGridView" + stringArray[i].ToString(); dgwDynamic.ScrollBars = ScrollBars.Both; dgwDynamic.Dock = DockStyle.Fill; dgwDynamic.DataBindingComplete += dgwDynamic_DataBindingComplete; /* Dynamic TabPage */ TabPage tpDynamic = new TabPage(); pageNumber = i + 1; tpDynamic.Name = "tabPage" + pageNumber.ToString(); //tpDynamic.Text = stringArray[i]; string[] splitString = stringArray[i].Split('$'); string firstSixCharacters = splitString[0]; //Keep first 6 characters string tabName = firstSixCharacters.Remove(0, 1); //Remove first character, resulting in 5 characters tpDynamic.Text = tabName; tpDynamic.TabIndex = i; // One newGridView per newTabPage tpDynamic.Controls.Add(dgwDynamic); // Add Dynamic DataGridView to Dynamic TabPage tabControl1.Controls.Add(tpDynamic); // Add Dynamic TabPage to TabControl dgwDynamic.DataSource = dt; // Add DataTable to Dynamic DataGridView }//End for loop dgwDynamic.CellFormatting += dgwDynamic_CellFormatting; // Change row colour

//I'm trying this but nothing happens dgwDynamic.Update(); dgwDynamic.Refresh(); tabControl1.Update(); tabControl1.Refresh(); } } }//Using }//End method ImportExcel private void dgwDynamic_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { List<String> myList = new List<String>(); myList.Add("Value1"); myList.Add("Value2"); myList.Add("Value3"); TabControl.TabPageCollection pages = tabControl1.TabPages; foreach (TabPage page in pages) { DataGridView grd = page.Controls.OfType<DataGridView>().FirstOrDefault(); foreach (DataGridViewRow row in grd.Rows) { foreach (DataGridViewCell cell in row.Cells) { if (cell.ColumnIndex == 13) //SET YOUR PARTICULAR COLUMN INDEX HERE!! { foreach (string item in myList) { if ((string)cell.Value == item) { row.DefaultCellStyle.BackColor = Color.Yellow; } }//foreach }//If }//foreach }//foreach }//foreach }//dgwDynamic_CellFormatting




How do I hide first column in every DataGridView using a CheckBox?

$
0
0

How do I hide the first column for all the DataGridViews in the tabs?

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            tabControl1.TabPages.Clear();
            createGridViews();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            dgwDynamic.Columns["Column1"].Visible = false;
        }

        DataGridView dgwDynamic;
        private void createGridViews()
        {
            int pageNumber = 0;
            for (int i = 0; i < 3; i++)
            {
                /* Dynamic DataGridView */
                dgwDynamic = new DataGridView();
                dgwDynamic.Name = "DataGridView" + i.ToString();
                dgwDynamic.ScrollBars = ScrollBars.Both;
                dgwDynamic.Dock = DockStyle.Fill;

                /* Dynamic TabPage */
                TabPage tpDynamic = new TabPage();
                pageNumber = i + 1;
                tpDynamic.Name = "tabPage" + pageNumber.ToString();

                string tabName = "TabPage" + pageNumber.ToString();

                tpDynamic.Text = tabName;

                tpDynamic.TabIndex = i;
                // One newGridView per newTabPage
                tpDynamic.Controls.Add(dgwDynamic); // Add Dynamic DataGridView to Dynamic TabPage
                tabControl1.Controls.Add(tpDynamic); // Add Dynamic TabPage to TabControl
                dgwDynamic.DataSource = GetTable(); // Add DataTable to Dynamic DataGridView

            }//End for loop
        }

        private static DataTable table;
        static DataTable GetTable()
        {
            // Here we create a DataTable with four columns.
            table = new DataTable();
            table.Columns.Add("Column1", typeof(string));
            table.Columns.Add("Column2", typeof(string));
            table.Columns.Add("Column3", typeof(string));

            // Here we add five DataRows.
            table.Rows.Add("Col1_Row1", "Col2_Row1", "Col3_Row1");
            table.Rows.Add("Col1_Row2", "Col2_Row2", "Col3_Row2");
            table.Rows.Add("Col1_Row3", "Col2_Row3", "Col3_Row3");
            table.AcceptChanges();
            return table;
        }
    }
I want to hide the first column for every DGW with one click? By the way, how do I also display the columns again when uncheck the CheckBox? Or maybe it would be more logical to hide the columns from the beginning and then check the CheckBox to have them displayed (so true=show columns, false=hide columns).



Viewing all 2535 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>