Trying to get my feet on the ground...

Dec 29, 2009 at 8:26 PM

Hello All,

I'm attempting to evaluate the SourceGrid for a specific task, which is to use it for managing data I'll storing in SQLite.

I just don't "get" the sourcegrid approach yet.

I'll need to use some ComboBox's to edit the data, standard LOV (list of values) stuff.

The sample code seems to address the creation of ComboBoxes at the cell level, vs. the column level. That seems silly for my purposes... is it?

Is there a way to define the grid, including the combobox cells,  before I know how many rows there will be?

Any pointers in the right direction would be much appreciated.

Thanks,

David

Coordinator
Dec 30, 2009 at 8:44 AM

SourceGrid has two major components - a normal Grid, where each cell is a different object, and a DataGrid, where only a single cell for each column exists.

DataGrid does not support spanning, and Grid does not scale very well with large amounts of data ( > 10k rows)

 

Dec 30, 2009 at 12:50 PM

So if I want to refer to the column, I say cell[0, <column>], and if I want to refer to the data area, I say cell[1, <column>]?

 

Dec 30, 2009 at 12:58 PM

I could really use a code snippet here... can you refer me to one or bang one out? I can't figure out how to map this:

grid1[r, 3] = new SourceGrid.Cells.Cell("Value 1", cbEditor) -which is in one of the examples, to what I need to do with a DataGrid.

Also, when using a combobox, is there an equivalent to the DataGridViewComboBox's DisplayMember and ValueMember? And can the combobox have a datasource?

All the example code seems to be aimed at the regular grid... unless I'm just missing it.

 

Coordinator
Dec 30, 2009 at 1:50 PM
davidbalick wrote:

I could really use a code snippet here... can you refer me to one or bang one out? I can't figure out how to map this:

grid1[r, 3] = new SourceGrid.Cells.Cell("Value 1", cbEditor) -which is in one of the examples, to what I need to do with a DataGrid.

Also, when using a combobox, is there an equivalent to the DataGridViewComboBox's DisplayMember and ValueMember? And can the combobox have a datasource?

All the example code seems to be aimed at the regular grid... unless I'm just missing it.

 

There are also examples with datagrid.  I am not sure if they really show you how to use combo box in datagrid though

Dec 30, 2009 at 1:57 PM

Darius, that is precisely my problem. I have no problem putting data into a datagrid via sql, since your examples are great for that.

But I cannot, for the life of me, get the combobox thing to work. That is what I need an example for. Can you help a noobie out?

Thanks,

David

 

Jan 4, 2010 at 7:53 PM

Not sure if what I have is what you want.  I am working in SQL Server express, created a generic form SourceGridDataForm.  You pass it a connection string, a query, and a set of lookup arrays out of which to create the data-driven combo box values. 

here are some code snippets, if this the kind of thing you think you might want, I will try to put something together.  Right now it is in a variety of places, not documented, basically I hacked it together, took me a while.  I posted a number of times relative to combobox stuff, did not get a lot of direction. 

// th is is code snippet for creating the lookup queries.

lookupSQL = new string[2];
columnName = new string[2];

lookupSQL[0] = "SELECT [StormSequenceGenerationMethodID],[StormSequenceGenerationMethodDescription] FROM StormSequenceGenerationMethod";
 sTempString = "Select [RepairPlanID],[RepairPlanDescription] From [" + SimulationGlobals.SimulationGlobals.gAlternativeDB + "].[dbo].[RepairPlans]";
 lookupSQL[1] = sTempString; // "Select [RepairPlanID],[RepairPlanDescription] From [NeahBay2].[dbo].[RepairPlans]";
 columnName = new string[2] { "StormSequenceGenerationMethodID", "RepairPlanID" };

// this is a wrapper for creating the form, given the lookup queries

private void CreateNewDataGridForm(string sDatabaseType, string sQuery, string MainIdentifier, string SecondaryIdentifier, string TertiaryIdentifier, bool bIsEditable, string[] lookupSQL, string[] columnName)
        {
            SourceGridDataForm.SourceGridDataForm datagridForm = new SourceGridDataForm.SourceGridDataForm();
            string sDatabaseName = "";
            // convert Stomrs, Application, etc. to the real database name
            sDatabaseName = GetDatabaseName(sDatabaseType);

            string sConnectionString = "Data Source=.\\SQLExpress;integrated security=true;Database=" + sDatabaseName + ";";
            datagridForm.SetConnectionString(sConnectionString);
            datagridForm.SetQueryText(sQuery);
            datagridForm.SetLookups(lookupSQL, columnName);
            datagridForm.TabText = MainIdentifier + "/" + SecondaryIdentifier + "/" + TertiaryIdentifier;
            datagridForm.Text = datagridForm.TabText;

            datagridForm.Show(dockPanel1, DockState.DockBottom);
            // datagridForm.Show();
            datagridForm.SetEditable(bIsEditable);
           
            datagridForm.ActivateSourceGridForm();

        }

I can provide you with the code for the form itself, that handles the comboboxes, if you are interested.

 

R. Males

Cincinnati, OH

 

Jan 4, 2010 at 8:07 PM

Thanks so much for this... will examine it closely later.

Here's a code snippet using the DataGridView... I'm looking to do the equivalent thing with the SourceGrid:

     dataGridView1.Columns.Add(MakeDgvCol("Media", "SELECT Id, Text FROM SOME_LOOKUP_TABLE"));

     public static DataGridViewColumn MakeDgvCol(string dataPropertyName, string sql)
        {
            SQLiteCommand cmd = new SQLiteCommand("SELECT Id, Text FROM SOME_LOOKUP_TABLE");
            DataTable dataTable = SqlUtil.PopulateDataTable(cmd); // DataAdapter.Fill, etc.
            DataGridViewComboBoxColumn cbo = new DataGridViewComboBoxColumn();
            cbo.AutoComplete = true;
            cbo.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
            cbo.DataSource = dataTable;
            cbo.ValueMember = dataTable.Columns[0].ColumnName;
            cbo.DisplayMember = dataTable.Columns[1].ColumnName;
            cbo.DataPropertyName = name;
            cbo.HeaderText = name;
            cbo.Name = name;
            cbo.SortMode = DataGridViewColumnSortMode.Automatic;
            return result;
        }

I just don't see how this incredibly common thing is done with the sourcegrid!! Probably me being thick...