Results 1 to 5 of 5

Thread: multibinding datagridtextcolumn

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2012
    Posts
    136

    multibinding datagridtextcolumn

    I'm back again. I've been working on improving my database handling and from that end it is looking good. One of the things I had to give up is using subselects and joins to get text from another table since then the DataAdapter.update() can't work.

    So I've been researching how to assign other values to the datagrid and discovered how to build the columns myself no problem as long as I bind to a column in me Datatable.

    I did run across mention of using databindings so I spent last night and today trying to get those working. Didn't take too long to get two words built into a sentence then a little later some math. That worked great with Textboxes and Textblocks. I still get told that my converter class doesn't exist in the namespace even though it works fine though.

    I'm at a dead end now since I am trying to multibind and do some math in a DataGridTextColumn. My converter just throws an exception saying I can't convert a named object into an int/double/whatever. I did a lot of looking and I am thinking the problem is that nothing is being sent IN that object (basically null) so no casting will work. Even Integer.tryparse() throws exceptions which is what it is supposed to prevent.

    I'm building the columns in XAML then assigning the datatable to the datagrid in codebehind. NO clue why it isn't working but then I have almost no clue what I am doing either.,

    XAML
    Code:
                <DataGrid Name="dg" IsReadOnly="False" AutoGenerateColumns="False" >
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Name" Binding="{Binding name}"/>
                        <DataGridTextColumn x:Name="MyGridColumn"
                                    Header="Amount"
                                    Width="*">
                            <DataGridTextColumn.Binding>
                                <MultiBinding Converter="{StaticResource ingAmountConvert}">
                                    <Binding Path="amount" />
                                    <Binding Path="stkpkg" />
                                </MultiBinding>
                            </DataGridTextColumn.Binding>
                        </DataGridTextColumn>
                        <DataGridTextColumn Header="Pkg" Binding="{Binding stkunit}"/>
                        <DataGridTextColumn Header="Name" Binding="{Binding name}"/>
                    </DataGrid.Columns>
                </DataGrid>
    Nothing in the code except dg.ItemsSource=dtUsers.Defaultview

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Dec 2012
    Posts
    136

    Re: multibinding datagridtextcolumn

    I've been messing around more and discovered that my datatable was actually empty (fixed but no help). Then I went back to two text boxes and a textblock and the converter seems to be the culprit now. Can't seem to convert the values() in any way.

    I tried if(double.tryparse() Cint() and ever just tried a for each s as string in values but always get the same casting error. I even gutted the converter and just hard coded a return value which seems to work but that is all I can seem to do. What is wrong with this? It is basically just the code vstudio created when I said Implements IMultiValueConverter
    Code:
    Public Class IngAmountConverter
        Implements IMultiValueConverter
    
        Public Function Convert(values() As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IMultiValueConverter.Convert
    
    
            Return 222.0
        End Function
    
        Public Function ConvertBack(value As Object, targetTypes() As Type, parameter As Object, culture As CultureInfo) As Object() Implements IMultiValueConverter.ConvertBack
            Throw New NotImplementedException()
        End Function
    End Class

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2012
    Posts
    136

    Re: multibinding datagridtextcolumn

    Ugh I sorted out the two textbox problem - I bound to non existant textboxes (Case matters!) I will have to really check my datagrid column for spelling and case too

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2012
    Posts
    136

    Re: multibinding datagridtextcolumn

    Ok so Imulticonverter is working fine in a textbox with two others but the Datagrid column bindings are sending nulls. I have no idea why - I really need help since obviously the bindings are wrong somehow. I checked the names again the database and even copied and pasted them to be absolutely sure but still not getting anything sent to the multiconverter.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2012
    Posts
    136

    Re: multibinding datagridtextcolumn

    Well what a waste of an afternoon (and a relief). Turned out it was working fine all along but I hadn't CanUserAddRows=false on the datagrid so an extra blank row was showing up which of course only had nulls to send. I finally gave up on trying to check values and just threw in a try/catch block and that let it run long enough to show one completed row and one blank one. So used to dealing with my own ineptitude I never dreamed I was doing things (almost) correctly all along.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width